public void DisconnectClient(string ip)
        {
            if (!IsRunning)
            {
                OnDisconnectClientCompletedEvent?.Invoke(ip, SocketServerResult.ServerNotRunning);

                return;
            }

            SocketServerResult sRes = SocketServerResult.None;

            try
            {
                IClientSocket client = this[ip];

                client.Close();

                _clientDic.Remove(ip);

                sRes = SocketServerResult.Success;
            }
            catch
            {
                sRes = SocketServerResult.Exception;
            }
            finally
            {
                OnDisconnectClientCompletedEvent?.Invoke(ip, sRes);
            }
        }
Beispiel #2
0
 public void Close()
 {
     if (null != m_socket)
     {
         m_socket.Close();
     }
     m_socket = null;
 }
Beispiel #3
0
 public void Run()
 {
     using (var stream = _socket.GetStream()) {
         var reader   = new StreamReader(stream);
         var writer   = new BinaryWriter(stream);
         var request  = _parser.Parse(reader);
         var handler  = _router.Route(request);
         var response = handler.Handle(request);
         response.Send(writer);
     }
     _socket.Close();
 }