First sample, EchoService

This guide will introduce how to create a simple command line socket application using SupperSocket application framework.

1. Create a new project named “EchoService” in a new empty solution
2. Add the projects “Common”, and "SocketBase" (which are belong to SuperSocket) into the solution, and then let the project “EchoService” reference them
3. Add session class and server class
EchoSession.cs
http://supersocket.codeplex.com/SourceControl/changeset/view/62405#1286433

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperSocket.SocketBase;

namespace EchoService
{
    public class EchoSession : AppSession<EchoSession>
    {
        public override void StartSession()
        {
            SendResponse("Welcome to EchoServer!");
        }

        public override void HandleExceptionalError(Exception e)
        {
            SendResponse("Server side error occurred!");
        }
    }
}

EchoServer.cs
http://supersocket.codeplex.com/SourceControl/changeset/view/62405#1286478

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperSocket.SocketBase;

namespace EchoService
{
    public class EchoServer : AppServer<EchoSession>
    {

    }
}



4. Add command class
ECHO.cs
http://supersocket.codeplex.com/SourceControl/changeset/view/62405#1286382

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperSocket.SocketBase.Command;

namespace EchoService.Command
{
    public class ECHO : StringCommandBase<EchoSession>
    {
        #region CommandBase<EchoSession> Members

        public override void ExecuteCommand(EchoSession session, StringCommandInfo commandInfo)
        {
            session.SendResponse(commandInfo.Data);
        }

        #endregion
    }
}

Command class must be public.

5. Build the project “EchoService” and then copy outputted assemblies to the output dir of the project “SocketService” (provided by SupperSocket, build it in advance please)

6. Update app.config of SocketService to use EchoService
SuperSocket.SocketService.exe.config
http://supersocket.codeplex.com/SourceControl/changeset/view/62405#1286366

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="socketServer" type="SuperSocket.SocketEngine.Configuration.SocketServiceConfig, SuperSocket.SocketEngine" />
  </configSections>
  <appSettings>
    <add key="ServiceName" value="EchoService" />
  </appSettings>
  <connectionStrings/>
  <socketServer>
    <servers>
      <server name="Default Echo Server" serviceName="EchoService" ip="Any" port="911" mode="Async" />
    </servers>
    <services>
      <service name="EchoService" type="EchoService.EchoServer, EchoService" />
    </services>
  </socketServer>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
</configuration>


Please note the "socketServer" node in above code.

7. Click “RunServer.bat” and then enter “start” to start the server, then you can test the echo server by telnet (you also can click "InstallService.bat" to intsall the server application as windows service, the service name is defined in appSetting of app.config with the key "ServiceName")


More samples in QuickStart have been included into source code of SuperSocket:
http://supersocket.codeplex.com/releases/view/59310

Last edited Mar 15, 2012 at 5:01 AM by kerryjiang, version 5

Comments

Eraknelo Nov 2 at 4:52 PM 
Hahaha, laughed my ass off at step 2 :D
Did anyone else notice?

nienawiedzony Jan 6, 2013 at 7:36 PM 
Maybe I'm retarded, but I can't get this working with the newest version (beta 1.5) - there's no StringCommandInfo class in an entire solution, so I've chosen to use another (implementing correct interfaces). Then when I follow the step 5 RunServer.bat gives me error and when I just run SuperSocket.SocketServer with the -c param from cmd manually, I get like a million lines exception's stack trace. Thanks for a great piece of software guys!

dinsdale247 Nov 12, 2012 at 7:24 AM 
ha ha, success. I have to copy my echoservice.dll file into the socketservice/bin/debug folder but it works...

JBridge Sep 26, 2012 at 7:05 PM 
followed echoservice step by step using vs2010 and .net4

when I run "RunServer.bat", got err in log:

2012-09-26 11:02:41,570 [4296] ERROR SuperSocket - Failed to initialize service EchoService!
System.BadImageFormatException: Could not load file or assembly 'EchoService' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'EchoService'
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
at System.Type.GetType(String typeName, Boolean throwOnError)
at SuperSocket.Common.AssemblyUtil.TryGetType(String type, Type& result, Exception& e) in C:\Projects\SuperSocket(1.4 SP5).Source\Common\AssemblyUtil.cs:line 57

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

jmacentee Oct 12, 2011 at 5:16 PM 
Just in case anyone else reads the above comment -- there was a discussion on the topic.

... found & fixed the same error using your suggestion. Windows 7 64 bit. Compile QuickStart\EchoService. On first run: System.Security.SecurityException. Right click on QuickStart\EchoService\bin\Debug\SuperSocket.SocketService.exe.config select "Properties". Click "Unblock". Run RunServer.bat again.

Watcha Jun 22, 2011 at 3:26 PM 
Hi,

When I follow these steps, or when I compile the project in 'QuickStart' in the download, I get the error message 'Unhandled Exception: System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for socketServer: Request failed.

---> System.Security.SecurityException: Request failed.

This is in Visual Studio 2010.