Exemple #1
0
 private void ClientReceiving(object pmMain = null)
 {
     try
     {
         while (this.working)
         {
             byte[] buffer         = new byte[1024];
             int    receivedLength = this.clientSocket.Receive(buffer);
             if (receivedLength > 0)
             {
                 if (!realmReceiveBuffer.Append(buffer.Take(receivedLength).ToArray()))
                 {
                     MLogger.NetworkLogger.Error("Receive buffer appending error occured : " + this.clientSocket.Handle);
                     this.StopSession();
                 }
             }
             else
             {
                 MLogger.NetworkLogger.Error("Realm client socket disconnected : " + this.clientSocket.Handle);
                 this.StopSession();
             }
         }
     }
     catch (Exception exp)
     {
         MLogger.NetworkLogger.Error("Realm client receiving exp :" + this.clientSocket.Handle + " " + exp.Message);
         this.StopSession();
     }
 }
        protected override void onRecv(byte[] data, int len)
        {
            _buffer.Append(data, 0, len);
            const int maxBufferSize = 0x10000000;

            if (_buffer.BufferSize > maxBufferSize)
            {
                _buffer.Delete(_buffer.Length);
            }

            int index = 0;

            while (index < _buffer.Length)
            {
                while (index + 8 <= _buffer.Length && (!isTaidMsgType(getUInt32(_buffer.Buffer, index)) || getUInt32(_buffer.Buffer, index + 4) >= 500))
                {
                    index++;
                }

                if (index + 8 <= _buffer.Length)
                {
                    int packetSize = 8 + (int)getUInt32(_buffer.Buffer, index + 4);
                    if (index + packetSize <= _buffer.Length)
                    {
                        parseCmd(_buffer.Buffer, index, packetSize);
                        index += packetSize;
                        continue;
                    }
                }
                break;
            }

            _buffer.Delete(index);
        }