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

//1

Initializes the winsock library if appropriate (Windows platform only)

//2

Creates an address object, which represents the IP address and port number that this server will be waiting for client connections on.

//3

Binds the server side socket to the address constructed in the first step.

//4

Waits for an incoming connection, assigning that connection to conn for later use.

//5

Constructs a time object, which represents the current date and time.

//6

Formats the time object as a string so we can easily send it to the client.

//7

Send the response.

//8

Close 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.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.