Tcp消息的处理本身是与Tcp消息传输过程独立的,是消息的两个不同阶段,从前面的会话生命周期我们已经知道消息的传输主要有SocketSession实现,而真正处理则交由AppSession实现,SuperSocket的层次划分也是非常清晰明了。

  SuperSocket消息处理主要流程:接收=》原始过滤=》协议解析=》命令路由并执行=》找不到命令则直接一分不动发给客户端

二 消息接收

1 开始接收

代码位置:AsyncSocketSession=》StartReceive

 1  private void StartReceive(SocketAsyncEventArgs e)
 2         {
 3             StartReceive(e, 0);
 4         }
 5 
 6         private void StartReceive(SocketAsyncEventArgs e, int offsetDelta)
 7         {
 8             bool willRaiseEvent = false;
 9 
10             try
11             {
12                 if (offsetDelta < 0 || offsetDelta >= Config.ReceiveBufferSize)
13                     throw new ArgumentException(string.Format("Illigal offsetDelta: {0}", offsetDelta), "offsetDelta");
14 
15                 var predictOffset = SocketAsyncProxy.OrigOffset + offsetDelta;
16 
17                 if (e.Offset != predictOffset)
18                 {
19                     e.SetBuffer(predictOffset, Config.ReceiveBufferSize - offsetDelta);
20                 }
21 
22                 if (IsInClosingOrClosed)
23                     return;
24 
25                 OnReceiveStarted();
26                 willRaiseEvent = Client.ReceiveAsync(e);
27             }
28             catch (Exception exc)
29             {
30                 LogError(exc);
31 
32                 OnReceiveError(CloseReason.SocketError);
33                 return;
34             }
35 
36             if (!willRaiseEvent)
37             {
38                 ProcessReceive(e);
39             }
40         }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2021-11-03
  • 2022-12-23
  • 2021-12-24
猜你喜欢
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2021-04-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案