Ejemplo n.º 1
0
 private void Receive(object o)
 {
     try
     {
         while (used)
         {
             BaseNetObject baseNetObject = NetBaseTool.ReceiveBaseNetObject(socket);
             if (baseNetObject is HeartBeat)
             {
                 receiveHeartBeat = true;
                 Logger.WriteLog("receive heartbeat confirm alive");
                 if (!useHeartBeat)
                 {
                     SendBaseNetObjects.Enqueue(new HeartBeat());
                 }
             }
             else
             {
                 ReceiveBaseNetObjects.Enqueue(baseNetObject);
             }
             Thread.Sleep(DELAY);
         }
     }
     catch (SocketException e)
     {
         if (t != null)
         {
             t.Stop();
         }
         Logger.WriteException(e, "心跳中断");
         used = false;
         return;
     }
 }
Ejemplo n.º 2
0
 private void Send(object o)
 {
     try
     {
         while (used)
         {
             if (SendBaseNetObjects.Count > 0)
             {
                 BaseNetObject baseNetObject = SendBaseNetObjects.Dequeue();
                 NetBaseTool.SendBaseNetObject(socket, baseNetObject);
             }
             Thread.Sleep(DELAY);
         }
     }
     catch (SocketException e)
     {
         if (t != null)
         {
             t.Stop();
         }
         Logger.WriteException(e, "心跳中断");
         used = false;
         return;
     }
 }