Пример #1
0
 public void LoginOut(ClientFather client)
 {
     if (_clientDict.ContainsKey(client.ID))
     {
         _clientDict[client.ID].IsLogin = false;
         _clientDict[client.ID].LoginOutTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
     }
 }
Пример #2
0
 public void Login(ClientFather client)
 {
     if (_clientDict.ContainsKey(client.ID))
     {
         _clientDict[client.ID] = client;
     }
     else
     {
         _clientDict.Add(client.ID, client);
     }
 }
Пример #3
0
        void SocketError(ClientFather obj, Exception ex)
        {
            if (obj.ConnSocket != null && obj.ConnSocket.Enabled)
            {
                obj.ConnSocket.Enabled = false;
                obj.ConnSocket.workSocket.Shutdown(SocketShutdown.Both);
                obj.ConnSocket.workSocket.Close();

                if (ClientErrorEvent != null)
                {
                    ClientErrorEvent.BeginInvoke(obj, ex, null, null);
                }
            }
        }
Пример #4
0
 void Receive(ClientFather obj)
 {
     try
     {
         obj.ConnSocket.workSocket.BeginReceive(obj.ConnSocket.buffer, 0, obj.ConnSocket.buffer.Length, SocketFlags.None, p =>
         {
             //接收处理逻辑
             string msg = ReceiveCallback(p, obj.ConnSocket);
             if (msg != null)
             {
                 var txdata = new TxData(msg);
                 if (ReceiveDataEvent != null)
                 {
                     ReceiveDataEvent.BeginInvoke(obj, txdata, null, null);
                 }
             }
             Receive(obj);
         }, obj);
     }
     catch (Exception ex)
     {
         SocketError(obj, ex.Message);
     }
 }
Пример #5
0
 /// <summary>
 /// 发送数据到指定终端
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="txdata"></param>
 /// <param name="sendCallback">发送后的回调函数</param>
 public void Send(ClientFather client, TxData txdata, AsyncCallback sendCallback)
 {
     lock (obj.sendLockObj)
     {
         SendClientObject sendObj = new SendClientObject
         {
             ID = Guid.NewGuid().ToString(),
             client = client,
             txData = txdata
         };
         Send(sendObj, sendCallback);
     }
 }
Пример #6
0
 //主动关闭客户端
 public void CloseClient(ClientFather obj)
 {
     if (obj.ConnSocket != null && obj.ConnSocket.Enabled)
     {
         obj.ConnSocket.Enabled = false;
         obj.ConnSocket.workSocket.Shutdown(SocketShutdown.Both);
         obj.ConnSocket.workSocket.Close();
         //ClientList.Remove(obj);
         if (ClientCloseEvent != null)
         {
             ClientCloseEvent.BeginInvoke(obj, null, null);
         }
     }
 }