Exemplo n.º 1
0
 /// <summary>
 /// Close the socket associated with the client.
 /// </summary>
 /// <param name="e">SocketAsyncEventArg associated with the completed send/receive operation.</param>
 private void CloseClient(AsyncUserToken token)
 {
     lock (token)
     {
         if (token == null || _clients.ContainsKey(token.SessionId) == false)
         {
             return;
         }
         try
         {
             DynamicBufferManager.Remove(token.SessionId);
             var args = token.AsynSocketArgs;
             //释放资源
             //this.semaphoreAcceptedClients.Release();
             //回收到pool中
             this.readWritePool.Push(args);
             RemoveClient(token.SessionId);
             ShowLog($"{token.Socket?.RemoteEndPoint?.ToString()} 连接已关闭");
             token.Dispose();
         }
         catch (Exception)
         {
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Disposes the instance of SocketClient.
 /// </summary>
 public void Dispose()
 {
     try
     {
         if (_heartBeatsTimer != null)
         {
             _heartBeatsTimer.Dispose();
             _heartBeatsTimer = null;
         }
         DynamicBufferManager.Remove(_sessionId);
         _socket?.Disconnect(false);
     }
     catch (Exception)
     {
     }
 }