/// <summary>
 /// 移除某个客户端
 /// </summary>
 /// <param name="client"></param>
 internal void RemoveClient(ClientThread client)
 {
     this._clients.Remove(client);
     //移除客户端后发送事件
     if (this.OnClientDisConnected != null)
     {
         //sender
         this.OnClientDisConnected(client, null);
     }
 }
 /// <summary>
 /// 向指定的客户发送信息
 /// </summary>
 /// <param name="remoteAddress">客户端地址</param>
 /// <param name="msg">要发送的信息</param>
 public bool Write(string remoteAddress, Packet packet)
 {
     for (int i = 0; i < this._clients.Count; i++)
     {
         ClientThread clientThread = (ClientThread)this._clients[i];
         if (clientThread.RemoteAddress.Equals(remoteAddress))
         {
             //这里
             return(clientThread.WritePacket(packet));
         }
     }
     return(false);
 }
 //监听
 private void _listen()
 {
     this._server.Listen(20);
     while (true)
     {
         //循环accept客户端的请求,然后开启新的现成进行数据交互
         Socket       client       = this._server.Accept();
         ClientThread clientThread = new ClientThread(client);
         //客户端线程异常事件
         clientThread.OnThreadException += clientThread_OnThreadException;
         //客户端线程停止事件
         clientThread.OnThreadStop     += clientThread_OnThreadStop;
         clientThread.OnReceviedPacket += clientThread_OnReceviedPacket;
         this._clients.Add(clientThread);
         //触发链接事件
         if (this.OnClientConnected != null)
         {
             //链接成功
             this.OnClientConnected(clientThread, null);
         }
         clientThread.Start();
     }
 }
Esempio n. 4
0
 public SocketEventArgs(ClientThread child)
 {
     this.ClientThread = child;
     this.address      = child.RemoteAddress;
 }