コード例 #1
0
        void SocketConnected(object sender, SocketEventArgs e)
        {
            Interlocked.Increment(ref connections);
            ServerInstrumentation.Current.Connect();
            SocketAsyncEventArgs args = socketArgsPool.CheckOut();

            bufferManager.CheckOut(args);
            var connection = new ServerConnection(e.Socket, args,
                                                  new DataReceivedCallback(DataReceived),
                                                  new DisconnectedCallback(Disconnected));
        }
コード例 #2
0
        private void DataReceived_Handler(object sender, SocketEventArgs e)
        {
            if (e.Data.Sum() > 0)
            {
                Datagram requestDatagram = DatagramResolver.ResolveRequest(e.Data);
                Datagram responseDatagram = null;

                if (requestDatagram != null)
                {
                    if (requestDatagram.Type == DatagramTypeEnum.HeartbeatRequest)
                    {
                        this.heartbeatCount = Interlocked.Increment(ref this.heartbeatCount);

                        responseDatagram = this.ProcessHeartbeat(requestDatagram);
                    }

                    if (requestDatagram.Type == DatagramTypeEnum.LoginRequest)
                    {
                        this.loginCount = Interlocked.Increment(ref this.loginCount);

                        responseDatagram = this.ProcessLogin(requestDatagram);
                    }

                    if (requestDatagram.Type == DatagramTypeEnum.BlacklistQueryRequest)
                    {
                        this.blacklistQueryCount = Interlocked.Increment(ref this.blacklistQueryCount);

                        responseDatagram = this.ProcessBlacklistQuery(requestDatagram);
                    }

                    if (requestDatagram.Type == DatagramTypeEnum.BlacklistDownloadRequest)
                    {
                        this.blacklistDownloadCount = Interlocked.Increment(ref this.blacklistDownloadCount);

                        responseDatagram = this.ProcessBlacklistDownload(requestDatagram);
                    }

                    if (requestDatagram.Type == DatagramTypeEnum.CurrencyRequest)
                    {
                        this.currencyCount = Interlocked.Increment(ref this.currencyCount);

                        responseDatagram = this.ProcessCurrency(requestDatagram);
                    }

                    this.LocalSocketServer.BeginSend(e.Socket, responseDatagram.FullDatagram);
                }
            }
        }
コード例 #3
0
        private void DataReceived_Handler(object sender, SocketEventArgs e)
        {
            if (e.Data.Sum() > 0)
            {
                Datagram requestDatagram  = DatagramResolver.ResolveRequest(e.Data);
                Datagram responseDatagram = null;

                if (requestDatagram != null)
                {
                    if (requestDatagram.Type == DatagramTypeEnum.HeartbeatRequest)
                    {
                        this.heartbeatCount = Interlocked.Increment(ref this.heartbeatCount);

                        responseDatagram = this.ProcessHeartbeat(requestDatagram);
                    }

                    if (requestDatagram.Type == DatagramTypeEnum.LoginRequest)
                    {
                        this.loginCount = Interlocked.Increment(ref this.loginCount);

                        responseDatagram = this.ProcessLogin(requestDatagram);
                    }

                    if (requestDatagram.Type == DatagramTypeEnum.BlacklistQueryRequest)
                    {
                        this.blacklistQueryCount = Interlocked.Increment(ref this.blacklistQueryCount);

                        responseDatagram = this.ProcessBlacklistQuery(requestDatagram);
                    }

                    if (requestDatagram.Type == DatagramTypeEnum.BlacklistDownloadRequest)
                    {
                        this.blacklistDownloadCount = Interlocked.Increment(ref this.blacklistDownloadCount);

                        responseDatagram = this.ProcessBlacklistDownload(requestDatagram);
                    }

                    if (requestDatagram.Type == DatagramTypeEnum.CurrencyRequest)
                    {
                        this.currencyCount = Interlocked.Increment(ref this.currencyCount);

                        responseDatagram = this.ProcessCurrency(requestDatagram);
                    }

                    this.LocalSocketServer.BeginSend(e.Socket, responseDatagram.FullDatagram);
                }
            }
        }
コード例 #4
0
        private void Accepted_Handler(object sender, SocketEventArgs e)
        {
            if (e.Socket.Connected)
            {
                if (this.Socket_Accepted != null)
                {
                    this.Socket_Accepted(null, null);
                }

                SocketAsyncEventArgs saea = this.LocalSaeaPool.Get();

                saea.AcceptSocket = e.Socket;
                saea.SetBuffer(0, this.BufferSize);

                if (!e.Socket.ReceiveAsync(saea))
                {
                    this.eCompleted(saea);
                }
            }
        }
コード例 #5
0
        private void Accepted_Handler(object sender, SocketEventArgs e)
        {
            if (e.Socket.Connected)
            {
                if (this.Socket_Accepted != null)
                {
                    this.Socket_Accepted(null, null);
                }

                SocketAsyncEventArgs saea = this.LocalSaeaPool.Get();

                saea.AcceptSocket = e.Socket;
                saea.SetBuffer(0, this.BufferSize);

                if (!e.Socket.ReceiveAsync(saea))
                {
                    this.eCompleted(saea);
                }
            }
        }
コード例 #6
0
 void SocketConnected(object sender, SocketEventArgs e)
 {
     Interlocked.Increment(ref connections);
     ServerInstrumentation.Current.Connect();
     SocketAsyncEventArgs args = socketArgsPool.CheckOut();
     bufferManager.CheckOut(args);
     var connection = new ServerConnection(e.Socket, args,
         new DataReceivedCallback(DataReceived),
         new DisconnectedCallback(Disconnected));
 }