1

我正在尝试为我正在从事的项目实施 Supersockets - https://supersocket.codeplex.com/。我有一台使用配置运行的服务器。在我的项目中

我参考过:

SuperSocket.Common,
SuperSocket.SocketBase,
SuperSocket.SocketEngine

我添加了以下配置部分:

 <configSections>
    <section name="superSocket" type="SuperSocket.SocketEngine.Configuration.SocketServiceConfig, SuperSocket.SocketEngine" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </configSections>
    <appSettings>
    <add key="ServiceName" value="SomeService" />
    </appSettings>
    <superSocket logFactory="ConsoleLogFactory"
              disablePerformanceDataCollector="true"
              maxWorkingThreads="500"
              maxCompletionPortThreads="500"
              minWorkingThreads="5"
              minCompletionPortThreads="5">
    <servers>
      <server name="SomeService"
              serverType="SomeService.Server.SomeService, SomeService"
              ip="192.168.1.107"
              port="4096"
              disableSessionSnapshot="true"
              clearIdleSession="false"
              maxConnectionNumber="10"
              sendWelcome="false">
      </server>
    </servers>
    <logFactories>
      <add name="ConsoleLogFactory"
           type="SuperSocket.SocketBase.Logging.ConsoleLogFactory, SuperSocket.SocketBase" />
    </logFactories>
    </superSocket>

我还创建了服务器和会话类,如下所示:

 namespace SomeService.Server
    {

    class SomeService: AppServer<SomeServiceSession>
    {

        protected override bool Setup(IRootConfig rootConfig, IServerConfig config)
        {

            return base.Setup(rootConfig, config);
        }

        protected override void OnStartup()
        {
            base.OnStarted();
        }

        protected override void OnStopped()
        {
            base.OnStopped();
        }

    }
    }

    namespace SomeService.Server
    {
    class SomeServiceSession : AppSession<SomeServiceSession>
    {
        protected override void OnSessionStarted()
        {
            // this.Send("Welcome to SuperSocket Telnet Server");
        }

        protected override void HandleUnknownRequest(StringRequestInfo requestInfo)
        {
            this.Send("Unknow request");
        }

        protected override void HandleException(Exception e)
        {
            this.Send("Application error: {0}", e.Message);
        }

        protected override void OnSessionClosed(CloseReason reason)
        {
            //add you logics which will be executed after the session is closed
            base.OnSessionClosed(reason);
        }
    }
    }

此时服务器运行并按预期侦听端口。这是我想用 SuperSocket http://imgur.com/rxKJbOD做什么的wireshark 表示。如果您在请求回复中看到一小部分数据:

.MSH|^~\&|MRI|ABC|||201403251406||QRY|173883426|P|2.1
QRD|201403251406|R|I|xxxxx|||25^RD|AB851656^|MPI
QRF|UPI||||
.

来自客户和

.MSH|^~\&|MRI|ABC|||201403251406||QRY|173883426|P|2.1
QRD|201403251406|R|I|xxxx|||25^RD|AB851656^|MPI
QRF|UPI||||
MSA|AA|173883426
.

来自服务器。返回的响应因请求和业务逻辑执行后创建的内容而异(但它始终是相同的格式 - HL7 en(dot)wikipedia(dot)org/wiki/Health_Level_7)。HL7 遵循 MLLP 消息格式,其中每条消息都以起始块代码 (0x0B) 开头,消息中的每个段都以回车码 (0x0D) 终止,并且每条消息都以结束块代码 (0x1C) 结束,后跟一个回车返回码 (0x0D)。一旦我收到请求,我就有一个解析值的业务逻辑类,调用一个 Web 服务获取数据并构造一个 tcp 回复。我想知道的是在 SuperSocket 中我可以在哪里有一个方法或事件侦听器来读取缓冲区并执行我的业务逻辑并返回同一会话的响应。我知道 SuperSocket 中有过滤器和命令之类的概念,但我无法弄清楚它们。任何帮助是极大的赞赏。如果您需要更多详细信息,请告诉我。

4

0 回答 0