コード例 #1
0
        private void Thread_WatchConnecting() //监听客户端连接的方法
        {
            string str1;

            while (bWatchAcceptFlag)
            {
                Thread.Sleep(100);
                try
                {
                    Socket connection = g_SocketServer.Accept();
                    str1 = connection.RemoteEndPoint.ToString();

                    ListMonitor client = new ListMonitor(this, connection);
                    g_lstConnectMonitorTab.Add(client); //增加收到的连接新客户端信息

                    client.RunRecv();                   //输入监听启动事件
                    //产生连接事件给外部
                    EventArgs_Connect args = new EventArgs_Connect();

                    if (OnConnect != null)   //产生连接事件,,给具体的监听类
                    {
                        OnConnect(this, args);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message.ToString());
                    continue;
                }
            }
        }
コード例 #2
0
 public void closeOneClient(int iLstIndex)   //断开一个客户连接
 {
     if ((iLstIndex >= 0) && (iLstIndex < g_lstConnectMonitorTab.Count))
     {
         ListMonitor sclient = g_lstConnectMonitorTab[iLstIndex];
         sclient.CloseSocket();
     }
 }
コード例 #3
0
 public void SendChange(ListMonitor ltClient, byte[] btRecMsg)//发送到信息,供监控类回调用
 {
     if (OnSendMsg != null)
     {
         EventArgs_Send args = new EventArgs_Send();
         args.btSendMsg   = btRecMsg;
         args.sSendTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
         args.sLogionName = ltClient.strLoginUserName;
         OnSendMsg(this, args);
     }
 }
コード例 #4
0
 public void RecvChange(ListMonitor ltClient, byte[] btReceiMsgBuf)//接收到回信息,供监控类回调用
 {
     if (OnRecvMsg != null)
     {
         EventArgs_Recv args = new EventArgs_Recv();
         args.btRecevByte = btReceiMsgBuf;
         args.sRecvMsg    = Encoding.Default.GetString(btReceiMsgBuf, 0, btReceiMsgBuf.Length);//接收的信息
         args.sRecvTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
         args.sLogionName = ltClient.strLoginUserName;
         args.sClientIP   = ltClient.ipaEndIP.ToString();
         args.iClientPort = ltClient.intEndPort;
         OnRecvMsg(this, args);
     }
 }
コード例 #5
0
 public void DisconnectChange(ListMonitor lClient)    //产生断开单一个连接的事件(供给监听类回调用)
 {
     try
     {
         g_lstConnectMonitorTab.Remove(lClient);
         if (OnDisconnect != null)
         {
             EventArgs_Disconnect args = new EventArgs_Disconnect();
             args.sImg = "";
             OnDisconnect(this, args);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message.ToString());
     }
 }