








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









Forouzan Notes COSC 6377 - Fall 2000 24-
Forouzan Notes COSC 6377 - Fall 2000 24-
Figure 24-1 (^) Data types
Forouzan Notes COSC 6377 - Fall 2000 24-
Figure 24-2 (^) Internet address structure
Forouzan Notes COSC 6377 - Fall 2000 24-
sin_len sin_family sin_port sin_addr sin_zero
...
Figure 24-3 (^) Socket address structure
Forouzan Notes COSC 6377 - Fall 2000 24-
MS byte LS byte
Figure 24-6 (^) Big-endian byte order
Forouzan Notes COSC 6377 - Fall 2000 24-
MS byte LS byte
Figure 24-7 (^) Little-endian byte order
Forouzan Notes COSC 6377 - Fall 2000 24-
Host byte order
Network byte order
16-bit
16-bit
32-bit
32-bit
Figure 24-8 (^) Byte-order transformation functions
Forouzan Notes COSC 6377 - Fall 2000 24-
u_short htons ( u_short host_short ) ;
u_short ntohs ( u_short network_short ) ;
u_long htonl ( u_long host_long ) ;
u_long ntohl ( u_long network_long ) ;
Figure 24-9 (^) Declarations for byte-order transformation
Forouzan Notes COSC 6377 - Fall 2000 24-
Figure 24-12 (^) Declaration for byte-manipulation functions
void memset ( void _dest_ , int chr , int len ) ;
void memcpy ( void _dest_ , const void _src_* , int len ) ;
int memcmp ( const void _first_* , const void _second_* , int len ) ;
Forouzan Notes COSC 6377 - Fall 2000 24-
Figure 24-13 (^) Declaration for gethostbyname
Forouzan Notes COSC 6377 - Fall 2000 24-
alias
h_aliases h_addrtype h_length h_addr_list
AF_INET 4
alias
h_name
. . .
address address . . .
Figure 24-14 (^) The hostent structure
name
Forouzan Notes COSC 6377 - Fall 2000 24-
Returns a socket descriptor if successful;−1 if error.
Figure 24-15 (^) Declaration for socket function
Forouzan Notes COSC 6377 - Fall 2000 24-
Returns 0 if successful; - 1 if error
Figure 24-18 (^) Declaration for listen function
Forouzan Notes COSC 6377 - Fall 2000 24-
int accept (int (^) sockfd , const struct sockaddr_in (^) _clientaddr_* , int (^) _clientaddrlen_* ) ;
Returns a socket descriptor if successful; - 1 if error
Figure 24-19 (^) Declaration for accept function
Forouzan Notes COSC 6377 - Fall 2000 24-
int sendto (int (^) sockfd , const void (^) _buf_* , int buflen , int (^) flags , const struct sockaddr_in _toaddr_* , int toaddrlen ) ;
Returns number of bytes sent if successful; - 1 if error
Figure 24-20 (^) Declaration for sendto function
Forouzan Notes COSC 6377 - Fall 2000 24-
int recvfrom (int (^) sockfd , const void (^) _buf_* , int (^) buflen , int (^) flags const struct sockaddr_in (^) _fromaddr_* , int (^) _fromaddrlen_* ) ;
Figure 24-21 (^) Declaration for recvfrom function
Returns number of bytes sent if successful; - 1 if error
Forouzan Notes COSC 6377 - Fall 2000 24-
Figure 24-24 (^) Declaration for close function
Forouzan Notes COSC 6377 - Fall 2000 24-
sendto (...)
socket (...)
bind (...)
Process
Repeat infinitely
recvfrom (...)
Server
Requests
Responses
socket (...)
sendto (...)
close (...)
Repeat as needed
recvfrom (...)
Clients
Each server serves many clients but handles one request at a time. Requests from different clients can be mingled together.
Figure 24-25 Socket interface for connectionless iterative server
Forouzan Notes COSC 6377 - Fall 2000 24-
socket (...) connect (...)
write (...)
close (...)
as neededRepeat
socket (...)
bind (...)
listen (...)
accept (...)
fork (...)
read (...)
write (...)
(listening)close
Process
Repeat infinitely
as neededRepeat
read (...)
Connection request
Parent server
Child server
request
response
Server
Client
each child server serves only one client.A parent server creates many children;
(accepting)close
(accepting)close
Figure 24-26 Socket interface for connection-oriented concurrent server
Forouzan Notes COSC 6377 - Fall 2000 24-
Client Server
a. After connect, before accept
b. After accept
c. After fork
d. After parent closes ephemeral port
e. After child closes well-known port
Parent
Parent
Parent
Parent
Parent
Child
Child
Child
Figure 24-27 Relationship between the client and the server