示例#1
0
 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);
             }
         }
     }
 }
示例#2
0
        public ServersideSession GetPeer(int peerIndex)
        {
            ServersideSession serversideSession = (ServersideSession)null;

            this._peers[peerIndex % this._readWriteThreadCount].TryGetValue(peerIndex, out serversideSession);
            return(serversideSession);
        }
示例#3
0
        private void RemovePeer(int peerNo)
        {
            ServersideSession peer = (ServersideSession)null;

            if (!this._peers[peerNo % this._readWriteThreadCount].TryRemove(peerNo, out peer))
            {
                return;
            }
            peer.Socket.Close();
            peer.OnDisconnected();
            this.OnRemoveConnection(peer);
            this._disconnectedPeers[peerNo % this._readWriteThreadCount].TryRemove(peer.Index, out peer);
        }
示例#4
0
        private void IncomingConnectionsTick()
        {
            TcpSocket incomingConnection = this._serverSocket.GetLastIncomingConnection();

            if (incomingConnection == null)
            {
                return;
            }
            ServersideSession serversideSession = this.OnNewConnection();

            ++this._lastUniqueClientId;
            serversideSession.InitializeSocket(this._lastUniqueClientId, incomingConnection);
            this._peers[this._lastUniqueClientId % this._readWriteThreadCount].TryAdd(this._lastUniqueClientId, serversideSession);
        }
示例#5
0
 protected abstract void OnRemoveConnection(ServersideSession peer);
示例#6
0
 internal void AddDisconnectedPeer(ServersideSession peer) => this._disconnectedPeers[peer.Index % this._readWriteThreadCount].TryAdd(peer.Index, peer);