Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

16.8 Server Implementation

Now we can implement the server. The server side equivalent of the DistWebArray class is DistWebArrayImpl. This class interprets the protocol and manages the underlying collection. Here is its declaration.

//1The parenthesis operator is the general interface for handling requests. The implementation of this operator extracts a string from istrm indicating the operation requested. The request is then delegated to the appropriate interface.
//2The collection itself is kept here.

The implementation uses only virtual streams; it is completely decoupled from the disposition of the data. This means we can use the same implementation with virtual streams attached to a file, for example, to read a set of initializing items. Also, we can use any type of virtual stream with this implementation.

The implementation of the member functions is straightforward.

The server is a simple iterative server, which eliminates the need for locking the collection while accessing it.

//1Instantiate an implementation to hold the collection and implement the protocol.
//2Start a listener to monitor the server port for incoming connections. As with the client programs, SERVER is a preprocessor symbol set in the makefile to the address where the server runs. An RWSocketListener accepts connections on a specified socket address. See the Tools.h++ Professional Class Reference for more information on the RWSocketListener class.
//3Receive the next incoming connection. A portal is created to represent the connection.
//4Attach the portal to a streambuf so that we can use virtual streams.
//5Pass the client's request on to the implementation.
//6Handle any errors that might occur by printing a message and giving up. This is not a great strategy for handling errors, but we use it here for simplicity. A better idea might be to separately catch any exceptions that are thrown inside the infinite loop, and handle those errors by simply closing the connection and continuing on. This strategy would handle situations like clients that died part way into the protocol.


Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.