我正在尝试为我正在处理的项目实现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);
}
}
}
此时服务器运行并按预期侦听端口。这是一个wireshark表示我想用SuperSocket http://imgur.com/rxKJbOD做什么。 如果您在请求中看到回复一个数据:
.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(点)维基百科(点)org / wiki / Health_Level_7)。 HL7遵循MLLP消息传递格式,其中每个消息以起始块代码(0x0B)开始,并且消息中的每个段以回车代码(0x0D)终止,并且每个消息由结束块代码(0x1C)终止,然后是运输返回码(0x0D)。一旦我得到请求,我有一个解析值的业务逻辑类,调用Web服务获取数据并构造一个tcp回复。我想知道的是,在SuperSocket中我可以有一个方法或事件监听器来读取缓冲区并执行我的业务逻辑并返回相同会话的响应。我知道在SuperSocket中有像过滤器和命令这样的概念,但我还是无法解决它们。任何帮助是极大的赞赏。如果您需要更多详细信息,请与我们联系。