Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Essential Networking Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

9.2 A Simple Synchronous Server

The primary job of a server is to accept client connections. This can be done through the use of the Berkeley Socket Adapter. Example 16 shows a simple daytime server:

Example 16: Daytime Server

//1Initializes the winsock library if appropriate (Windows platform only)
//2Creates an address object, which represents the IP address and port number that this server will be waiting for client connections on.
//3Binds the server side socket to the address constructed in the first step.
//4Waits for an incoming connection, assigning that connection to conn for later use.
//5Constructs a time object, which represents the current date and time.
//6Formats the time object as a string so we can easily send it to the client.
//7Send the response.
//8Close the connection to the client and wait for further client connections.

Example 16 could be further extended to provide some exception handling. Placing a simple try/catch inside the loop allows for communication errors to be easily handled, as illustrated below:



Previous fileTop of DocumentContentsIndex pageNext file

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.