Esempio n. 1
0
 private void HandleRcvData(WeChatLink.StateObject so, int readLen)
 {
     if (this.haveRcvdLen + readLen < this.packetDataLen)
     {
         this.haveRcvdLen += readLen;
         Array.Copy(so.buffer, this.receivedByte, readLen);
         this.AsynRecive(so.workSocket);
     }
     else
     {
         Array.Copy(so.buffer, this.receivedByte, this.packetDataLen - this.haveRcvdLen);
         this.haveRcvdLen = this.packetDataLen;
         this.ParseActData();
         this.CloseSocket(so.workSocket);
     }
 }
Esempio n. 2
0
        private void ReceiveCallback(IAsyncResult asyncResult)
        {
            Debug.Log(string.Empty);
            WeChatLink.StateObject stateObject = (WeChatLink.StateObject)asyncResult.get_AsyncState();
            Socket workSocket = stateObject.workSocket;

            try
            {
                int num = workSocket.EndReceive(asyncResult);
                if (num > 0)
                {
                    if (this.firstReceive)
                    {
                        if (num > 4)
                        {
                            this.firstReceive = false;
                            byte[] array = new byte[4];
                            Array.Copy(stateObject.buffer, array, 4);
                            this.packetDataLen = BitConverter.ToInt32(array, 0);
                            this.packetDataLen = IPAddress.NetworkToHostOrder(this.packetDataLen) + 4;
                            this.receivedByte  = new byte[this.packetDataLen];
                            this.HandleRcvData(stateObject, num);
                        }
                        else
                        {
                            this.CloseSocket(workSocket);
                        }
                    }
                    else
                    {
                        this.HandleRcvData(stateObject, num);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Log(ex.get_Message());
                this.CloseSocket(workSocket);
            }
        }
Esempio n. 3
0
 private void AsynRecive(Socket socket)
 {
     Debug.Log(string.Empty);
     WeChatLink.StateObject stateObject = new WeChatLink.StateObject();
     stateObject.workSocket = socket;
     try
     {
         IAsyncResult asyncResult     = socket.BeginReceive(stateObject.buffer, 0, 1024, 0, null, stateObject);
         WaitHandle   asyncWaitHandle = asyncResult.get_AsyncWaitHandle();
         try
         {
             if (!asyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds((double)this.sendRcvTimeOut)))
             {
                 Debug.Log("Receive Time Out:" + this.sendRcvTimeOut.ToString());
                 this.CloseSocket(socket);
             }
             else
             {
                 this.ReceiveCallback(asyncResult);
             }
         }
         catch (Exception ex)
         {
             Debug.Log(ex.get_Message());
             this.CloseSocket(socket);
         }
         finally
         {
             asyncWaitHandle.Close();
         }
     }
     catch (Exception ex2)
     {
         Debug.Log(ex2.get_Message());
         this.CloseSocket(socket);
     }
 }