예제 #1
0
        private void OperationCompleted(object sender, SocketAsyncEventArgs e)
        {
            e.Completed -= OperationCompleted;

            switch (e.LastOperation)
            {
            case SocketAsyncOperation.Receive:
                ProcessNetwork(e);

                SocketPool.Add(e);
                break;

            case SocketAsyncOperation.Send:
                IPacket packet = e.UserToken as IPacket;

                if (packet is DisconnectPacket)
                {
                    Server.DisconnectClient(this);
                }

                e.SetBuffer(null, 0, 0);
                break;

            case SocketAsyncOperation.Disconnect:
                Connection.Close();

                break;
            }

            if (Connection != null)
            {
                if (!Connection.Connected && !Disconnected)
                {
                    Server.DisconnectClient(this);
                }
            }
        }