Ejemplo n.º 1
0
 void accept()
 {
     TcpListener listener = this.listener;
     while (true)
     {
         TcpClient tcpclient = listener.AcceptTcpClient();
         SvrClient client = new SvrClient(tcpclient.Client, this);
         logLine("客户端(", client.ep, ")已连接。");
         new Thread(client.start).Start();
         if (newClient != null)
             newClient(client);
         clients.Add(client);
         client.disLinked += (cli) => clients.Remove(client);
     }
 }
Ejemplo n.º 2
0
 void server_newClient(SvrClient client)
 {
     myinvoke(() =>
     {
         var tsmi = new ToolStripMenuItem(client.ep);
         tsmi.Click += (a1, a2) =>
         {
             try
             {
                 client.Client.Close();
             }
             catch (Exception ex)
             {
                 logLine("断开连接时发生错误:", ex.Message);
             }
         };
         client.disLinked += (cli) =>
         {
             myinvoke(() =>
             {
                 listClientToolStripMenuItem.DropDownItems.Remove(tsmi);
                 f5Title();
             });
         };
         listClientToolStripMenuItem.DropDownItems.Add(tsmi);
         f5Title();
     });
 }