Beispiel #1
0
 public override void Close()
 {
     if (isActive)
     {
         isActive = false;
         if (ClientDisconnected != null)
         {
             ClientEventArgs args = new ClientEventArgs();
             args.Client             = this.Name;
             args.RemoteIpPortString = this.RemoteIpPortString;
             ClientDisconnected(args);
         }
         socket.Close();
     }
 }
Beispiel #2
0
 /// <summary>
 /// 关闭客户端
 /// </summary>
 public override void Close()
 {
     if (isActive)
     {
         isActive = false;
         socket.Close();
         socket.Dispose();
         if (ClientDisconnected != null)
         {
             ClientEventArgs args = new ClientEventArgs();
             args.Client = this.Name;
             ClientDisconnected(args);
         }
     }
 }
        private void Accept(SocketAsyncEventArgs args)
        {
            AsyncSession session = new AsyncSession(args.AcceptSocket);

            sessions.Add(session.RemoteIpPortString, session);
            session.ClientDisconnected += DisconnectedClient;
            session.DataReceived       += DataReceived;
            session.SysCommandReceived += Sys_CommandReceived;
            if (ClientConnected != null)
            {
                ClientEventArgs clientArgs = new ClientEventArgs();
                clientArgs.RemoteIpPortString = session.RemoteIpPortString;
                //连接成功后执行事件
                ClientConnected(clientArgs);
            }
        }
 void DisconnectedClient(ClientEventArgs e)
 {
     StopClient(e.RemoteIpPortString);
 }