private void MessagingTick() { foreach (ConcurrentQueue <IncomingServerSessionMessage> incomingMessage in this._incomingMessages) { int count = incomingMessage.Count; for (int peerNo = 0; peerNo < count; ++peerNo) { IncomingServerSessionMessage result = (IncomingServerSessionMessage)null; incomingMessage.TryDequeue(out result); ServersideSession peer = result.Peer; NetworkMessage networkMessage = result.NetworkMessage; try { networkMessage.BeginRead(); byte id = networkMessage.ReadByte(); if (!peer.ContainsMessageHandler(id)) { networkMessage.ResetRead(); peer.OnMessageReceived((INetworkMessageReader)networkMessage); } else { MessageContract messageContract = MessageContract.CreateMessageContract(peer.GetMessageContractType(id)); messageContract.DeserializeFromNetworkMessage((INetworkMessageReader)networkMessage); peer.HandleMessage(messageContract); } } catch (Exception ex) { this.RemovePeer(peerNo); } } } }
public void HandleNetworkMessage(NetworkMessage networkMessage) { byte key = networkMessage.ReadByte(); Type messageContractType = this.MessageContractTypes[key]; MessageContract messageContract = MessageContract.CreateMessageContract(messageContractType); Debug.Print("Message with id: " + (object)key + " / contract:" + (object)messageContractType + "received and processing..."); messageContract.DeserializeFromNetworkMessage((INetworkMessageReader)networkMessage); this.HandleMessage(messageContract); }