NetworkServer - an easily configurable RemObjects SDK server component

Introduction

In the previous article I’ve described how to create a RemObjects SDK server and set up the needed server components and tie them together.

The main purpose of the RemObjects SDK and Data Abstract frameworks is to simplify the development of distributed applications, yet some of the tasks needed to create a server application are the same for each server (f.e. server startup code, network component with server channel, messages, session manager etc).

Last year we introduced the ApplicationServer helper class (a unified base class for RemObjects SDK-based servers), so you can concentrate on the server’s business logic, not on writing the same (most of the time) server application startup code with all these checks like “are other instances of the server already running”, “do we need to start as a Windows Service” etc.

Now it is the time to make one more step forward and take a look at another core server application part that is again implemented in the same way as most of the server applications – the network connectivity part.

Network connectivity components include the server channel, one or more server messages, the session manager, event sinks, the event queue manager, the ZeroConf support component, etc. It is sometimes boring and error-prone to properly set them all up manually, and f.e. changing the server channel type can be a lot harder than it ought to be.

So we decided to implement and implemented a feature called ‘Server Reconfiguration System’. In short, this new feature allows to set the server connectivity parameters via its configuration file:

So there is no need anymore to rebuild the server application to change the Server Channel port, its type (i.e. protocol), or even to change the session storage from memory to Olympia Server.
And for sure, the generated components can be accessed via code and customized as needed.

Let’s take a look at this new feature in action. As the only difference is how the server network connectivity is configured in step 7, please refer to the RemObjects SDK Beginners Guide for steps 1 – 6.

Server Application

  1. Open the code-behind file for the main form (remember that our server app is intentionally primitive, so no properly layered architecture or ‘Run As Windows Service’ support is available here) and add the following private field:

private RemObjects.SDK.Server.INetworkServer server;

Also modify the form constructor:

public Form1() { InitializeComponent(); this.server = new RemObjects.SDK.Server.NetworkServer(); this.server.LoadDefaultConfiguration(); this.server.Start(); }

Now we have to provide the license information for the server components. To do this, add a file named licenses.licx to the server application project and set its Build Action to Embedded Resource. This file should contain the following text:

RemObjects.SDK.Server.IpTcpServerChannel, RemObjects.SDK.Server RemObjects.SDK.Server.IpSuperHttpServerChannel, RemObjects.SDK.Server RemObjects.SDK.Server.IpHttpServerChannel, RemObjects.SDK.Server RemObjects.SDK.Server.NamedPipeServerChannel, RemObjects.SDK.Server RemObjects.SDK.Server.LocalServerChannel, RemObjects.SDK.Server RemObjects.SDK.Server.HttpSysServerChannel, RemObjects.SDK.Server RemObjects.SDK.Server.HttpSysSuperHttpServerChannel, RemObjects.SDK.Server RemObjects.SDK.Server.SuperTcpServerChannel, RemObjects.SDK.Server RemObjects.SDK.Server.EventSinkManager, RemObjects.SDK.Server RemObjects.SDK.Server.MasterServerSessionManager, RemObjects.SDK.Server RemObjects.SDK.Server.MemoryMessageQueueManager, RemObjects.SDK.Server RemObjects.SDK.Server.MemorySessionManager, RemObjects.SDK.Server RemObjects.SDK.Server.OlympiaMessageQueueManager, RemObjects.SDK.Server RemObjects.SDK.Server.OlympiaServerSessionManager, RemObjects.SDK.Server

At build time the license compiler will embed the needed license information into the server application based on the class names provided in this file.

The server application can now be started. It will use the default settings (i.e. the Http Server Channel will be listening on port 8099 and Binary Message will be used to communicate with the client applications).

  1. Add the Application Configuration File item to the server app project and add the following settings:

Note: To ensure that the .NET application config file handlers will be able to properly load custom config sections, set the Copy Local property of all referenced RemObjects SDK assemblies to true.

After restart the server application will expose its services via the SuperHttp Server Channel listening on port 8101. And this without a single code line changed.

Now it is possible to change the Server Channel protocol (HTTP, SuperHTTP, TCP, SuperTCP), the port it is listening to and other options without the need to rebuild the server application.

A full list of available options will be provided in the corresponding Wiki article.

Conclusion

The introduction of the NetworkServer class and the corresponding infrastructure allows to easily create highly configurable RemObjects SDK server applications.