Esempio n. 1
0
            private void ProcessReceivedData(byte[] data, WebSocketSharp.Opcode messageType)
            {
                lock (this) {
                    this.m_heartbeatTime         = 0f;
                    this.m_missingHeartBeatCount = 0;
                }

                if (messageType == WebSocketSharp.Opcode.Close)
                {
                    this.Close();
                    return;
                }

                if (messageType == WebSocketSharp.Opcode.Ping || messageType == WebSocketSharp.Opcode.Pong)
                {
                    return;
                }

                MemoryStream stream = new MemoryStream(data);

                try{
                    stream.Position = 0;
                    int    packetId;
                    object packet = m_NetworkChannelHelper.DeserializePacket(stream, out packetId);                    //true to test
                    if (packet != null)
                    {
                        GameEntry.Event.Fire(this, ReferencePool.Acquire <WebSocketReceivedPacketEventArgs>().Fill(this, packetId, packet));
                    }
                }
                catch (Exception exception) {
                    m_Active = false;
                    if (NetworkChannelError != null)
                    {
                        NetworkChannelError(this, NetworkErrorCode.DeserializePacketError, exception.ToString());
                        return;
                    }

                    throw;
                }
                finally{
                    stream.Dispose();
                }
            }