This example shows you how to build another simple server. The basic structure is very similar to the Basic Echo Server
example and you should go and read about that first and have a good understanding of how everything fits together. This document will only cover the differences between the Basic Echo Server
example and this example.
This example is shipped with all licensed versions of The Server Framework and it requires the core server framework libraries (see here
for licensing options). You can always download the latest version of this example from here
; and although you will need the correct libraries to be able to build it you can look at the example code and see how it works and perhaps get ideas from it. A compiled, unicode release, build of this example is available on request if you require it for performance analysis of the framework.
The main difference between this server and the Basic Echo Server
is that this server implementation does not derive from a server base class. It only derives from a server callback class. Rather than using our server object as the server we simply pass it to an instance of one of the standard server classes and that object uses our callbacks. The main changes are in
where we have code like this:
commandLine.NoWelcomeMessage() ? "" : "Welcome to echo server\r\n");
Rather than just this:
commandLine.NoWelcomeMessage() ? "" : "Welcome to echo server\r\n",
The advantage of this method is that you can reuse the callback class to listen on multiple ports by passing it to multiple instances of server objects. You don't need a destructor that waits for the server base class to shut down before continuing with its own destruction (see the echo server documentation
for more details) and it's just a bit 'nicer' as designs go. Since the ability to compose the code in this way has only been available in the framework for a short time most of the example servers do not do things this way, but, instead, derive from a server class as well as from a callback interface. The fact that the examples do this is merely due to historical reasons and should not be taken as an indication that we don't think that this is a valid way to structure the code...