Stream ServerClient Design

 < Day Day Up > 



Stream Server/Client Design

The stream server and client utilize a TCP connection to communicate the date and time information from the server to the client. The data flow diagram illustrating the Sockets API calls is shown in Figure 15.1.

click to expand
Figure 15.1: Stream server/client data flow.

In order to accept client connections, the server must create a socket, bind a known name to it, and then use the listen call to specify its willingness to accept connections. Similarly, the client must also create a socket using the socket function in order to communicate.

Before any communication can occur, the sockets must be connected. From the server perspective, this implies an accept call that creates a new client socket at the server through the listening socket. Recall that the listening socket exists only to accept incoming connections. Communication to the client occurs only through the newly created socket returned by the accept call. From the client, the connect call connects the two socket endpoints together to allow them to communicate.

The recv and write calls illustrate data communication in this example. These calls could also be read and send, depending upon the desire of the implementer. In Figure 15.1, we see that the server writes the current time to the client, which is read by the client using the recv call.

Finally, the close call is used to terminate the connection. Closing the socket is managed by both ends, because each must close their sockets to completely close the conduit between them.



 < Day Day Up > 



BSD Sockets Programming from a Multi-Language Perspective
Network Programming for Microsoft Windows , Second Edition (Microsoft Programming Series)
ISBN: 1584502681
EAN: 2147483647
Year: 2003
Pages: 225
Authors: Jim Ohlund

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net