Let your AppServer run

Run your AppServer in SocketService

SuperSocket provides a project called as "SocketService", which is a shell where your AppServer can run in. SocketService allow your AppServer run as a console application or a windows service (require registration).

There are two ways to run your AppServer in SocketService:

1. Copy your AppServer's assembly into SocketService project's binary output directory

2. Reference the SocketService project in your AppServer project. If you want to work in this way, you need create a new application configuration file named "SuperSocket.SocketService.exe.config", because the VS.NET will not copy the SocketService project's application configuration file into your project's output directory.

No matter which way will you want to follow, you must add your socket server definition in the application configuration file according your requirement before you start the server.

There is a configuration sample:

 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="socketServer" type="SuperSocket.SocketEngine.Configuration.SocketServiceConfig, SuperSocket.SocketEngine"/>
    </configSections>
    <appSettings>
        <add key="ServiceName" value="BroardcastService"/>
    </appSettings>
    <socketServer loggingMode="IndependantFile">
        <servers>
            <server name="BroardcastServer"
                    serviceName="BroardcastService"
                    ip="Any" port="911" mode="Async">
            </server>
        </servers>
        <services>
            <service name="BroardcastService"
                     type="SuperSocket.QuickStart.BroadcastService.BroadcastServer, SuperSocket.QuickStart.BroadcastService" />
        </services>
    </socketServer>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
    </startup>
</configuration>

 

 

Basically, there are two key points to define your socket server:

1)  Define your services:

 

        <services>
            <service name="BroardcastService"
                     type="SuperSocket.QuickStart.BroadcastService.BroadcastServer, SuperSocket.QuickStart.BroadcastService" />
        </services>

 

 The services are AppServers you can use in this application, you should add your service node with your implemented AppServer's full type name and it's friendly name.

2)  Define your servers:

 

       <servers>
            <server name="BroardcastServer"
                    serviceName="BroardcastService"
                    ip="Any" port="911" mode="Async">
            </server>
        </servers>

 

After you add the services, you can add your server instance base your services. One server xml node stands for one socket server instance. The attribute "serviceName" of the server element is required for we must specify a service for one server. There are lot's attributes in the server elemen, for example, name, ip and port which are required fields. There are lots  of other optional attributes we can define. You can find all description for those attributes on the documentation page: http://supersocket.codeplex.com/wikipage?title=Basic%20configuration&referringTitle=Documentation

 

After you finish your configuration, you can start your application now.

1) Start your server as console application

 Click the bat file "RunServer.bat" can run SuperSocket as Console Application

2) Start your server as windows service

 SocketService project provide two bat for windows service issues, InstallService.bat is used for installing SuperSocket as windows service and the UninstallService.bat is used for unstalling the windows service.

 

You also can run SuperSocket in your own application container.

Added SuperSocket's references into your container project, and then add the following code into the container application's startup entry.

Anyway, your socket server definition in configuration file is required.

 

LogUtil.Setup();
SocketServiceConfig serverConfig = ConfigurationManager.GetSection("socketServer") as SocketServiceConfig;
if (!SocketServerManager.Initialize(serverConfig))
{
     return;
}

if (!SocketServerManager.Start())
{
     SocketServerManager.Stop();
     return;
}

Anyway, please don't forget configuration node of SuperSocket and configuration file of log4net in directory "/Config".

Last edited Mar 12, 2012 at 4:07 AM by kerryjiang, version 13

Comments

No comments yet.