Presentation is loading. Please wait.

Presentation is loading. Please wait.

Read() recv() connection establishment Server (connection-oriented protocol) blocks until connection from client Client socket() bind() listen() accept()

Similar presentations


Presentation on theme: "Read() recv() connection establishment Server (connection-oriented protocol) blocks until connection from client Client socket() bind() listen() accept()"— Presentation transcript:

1 read() recv() connection establishment Server (connection-oriented protocol) blocks until connection from client Client socket() bind() listen() accept() read() recv() write() send() socket() connect() write() send() process request data (request) data (reply) Socket system calls for connection-orientedprotocol

2 Server (connectionless protocol) socket() blocks until data received from client bind() recvfrom() sendto() socket() bind() sendto() recvfrom() process request data (request) data (reply) Client Socket system calls for connectionless protocol Not necessary in UDP!!

3 Socket system call r int sockfd = socket (int family, int type, int protocol r Family: AF_UNIX, AF_INET; Type: SOCK_STREAM, SOCK_DGRAM, SOCK_RAW struct sockaddr { unsigned short sa_family; //specifies the address type char sa_data[14]; //specifies the address value }; struct sockaddr_in { short sin_family; unsigned shortsin_port; 16 bit struct in_addrsin_addr; 32 bit{ unsigned long s_addr; } char sin_zero[8]; };

4 Network Byte Order Functions Example: struct sockaddr_in sin; sin.sin_family = AF_INET; sin.sin_port = htons(9999); sin.sin_addr.s_addr = inet_addr(“130.233.224.13”); inet_aton(“130.233.224.13”, &sin.sin_addr); unsigned short htons(unsigned short); unsigned short ntohs(unsigned short); unsigned long htonl(unsigned long); unsigned long ntohl(unsigned long);

5 Server system calls r int bind(int sockfd, struct sockaddr *myaddr, int addrlen) r int listen(int socket, int qlength) r !newsockfd = accept(int sockfd, void* peer, int *addrlen) r int getpeername(int sockfd, struct sockaddr *addr, int *addrlen); r struct hostent *gethostbyaddr(const char peer_addr, int len, int type); r ! (char*) socaddr_in.sin_addr, name in hostent->h_name

6 Client system calls r int connect(int sockfd, struct sockaddr* servaddr, int addrlen) r struct hostent *gethostbyname(const char *name); r ! addr.sin_addr = *((struct in_addr *) hostent->h_addr); r write or read(fd, buff_ptr, num_bytes) r int send(int s, const char *msg, int len, int flags) r int recv(int s, char *buf, int len, int flags) r flags: MSG_PEEK, MSG_OOB etc. r close(int socket), shutdown(int socket, int how)


Download ppt "Read() recv() connection establishment Server (connection-oriented protocol) blocks until connection from client Client socket() bind() listen() accept()"

Similar presentations


Ads by Google