Datagram ServerClient Design

 < Day Day Up > 



Datagram Server/Client Design

The datagram server and client utilize a UDP connection to communicate the date and time information from the server to the client. Recall from the stream server that a connection takes place to create a virtual circuit between the client and server. With datagram communication, this is not the case. Therefore, we must alter the communication in order to make the server aware of the client’s request. The data flow diagram illustrating the Sockets API calls is shown in Figure 15.2.

click to expand
Figure 15.2: Datagram server/client data flow.

At the server, we set up by creating our socket and then binding a name to it so that the client can locate it. The client similarly creates a socket in order to communicate. Note that the datagram server does not use listen or accept—these are stream-specific calls that are never used by datagram sockets.

The server then uses a recvfrom call to await a client datagram. This is necessary so that the server knows when a client desires the time and date information. Because datagram sockets are unconnected, some way is needed to identify the client request. We’ve chosen this method because it’s simple and provides us with the necessary client information at the server. Once the client sends a NULL message to the server, the server receives this message and, using the recvfrom call, can identify the source of the message. This message is then used by the server in the sendto call to return the time and date information. Note the symmetry in Sockets API functions for the datagram server.

Finally, both the datagram client and server applications use the close function to end the socket session.



 < 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