Example #1
0
 public void Disconnect()
 {
     if (Information.IsNothing(_socket))
     {
         return;
     }
     if (IsRuning)
     {
         _isRuning = false;
         OnDisconnectedEvent?.Invoke(this, EventArgs.Empty);
         Disconnected();
     }
     try
     {
         if (_socket.Connected)
         {
             _socket.Close();
         }
         _socket.Dispose();
     }
     finally
     {
         _socket   = null;
         _protocol = null;
     }
 }
Example #2
0
 public AConnection(Socket socket, MessageProtocol protocol)
 {
     log       = LogManager.GetLogger(GetType());
     _buffer   = new byte[16384];
     _clientId = ConnectionIDFactory.NextID();
     _protocol = protocol;
     _ip       = socket.RemoteEndPoint.ToString();
     _socket   = socket;
 }