public static void DisconnectConnections()
 {
     foreach (ClientConnection connection in ClientConnectionManager.m_connections.Values)
     {
         TcpServerSocket.Disconnect(connection);
     }
 }
Example #2
0
        public void ReceiveData()
        {
            if (!this.Destructed)
            {
                this.m_receiveBuffer.Write(this.m_receiveAsyncEventArgs.Buffer, this.m_receiveAsyncEventArgs.BytesTransferred);

                int length = this.m_receiveBuffer.Size();

                do
                {
                    int read = this.Messaging.OnReceive(this.m_receiveBuffer.GetBuffer(), length);

                    if (read <= 0)
                    {
                        if (read == -1)
                        {
                            TcpServerSocket.Disconnect(this);
                        }
                        break;
                    }

                    this.m_receiveBuffer.Remove(read);
                } while ((length = this.m_receiveBuffer.Size()) > 0);
            }
        }
        private static void OnReceive(object sender, SocketAsyncEventArgs args)
        {
            ClientConnection clientConnection = (ClientConnection)args.UserToken;

            if (clientConnection != null)
            {
                try
                {
                    do
                    {
                        if (args.SocketError != SocketError.Success || args.BytesTransferred <= 0)
                        {
                            TcpServerSocket.Disconnect(clientConnection);
                            break;
                        }

                        clientConnection.ReceiveData();
                    } while (!clientConnection.Destructed && !clientConnection.Socket.ReceiveAsync(args));
                }
                catch (SocketException)
                {
                    TcpServerSocket.Disconnect(clientConnection);
                }
                catch (Exception exception)
                {
                    Logging.Error("TcpServerSocket.onReceive - unhandled exception thrown : " + exception);
                    TcpServerSocket.Disconnect(clientConnection);
                }
            }
        }
        private static void OnSend(object sender, SocketAsyncEventArgs args)
        {
            if (args.SocketError != SocketError.Success)
            {
                TcpServerSocket.Disconnect((ClientConnection)args.UserToken);
            }

            args.Dispose();
        }
        private static void Update()
        {
            while (ClientConnectionManager.m_started)
            {
                foreach (ClientConnection connection in ClientConnectionManager.m_connections.Values)
                {
                    if (!connection.MessageManager.IsAlive())
                    {
                        TcpServerSocket.Disconnect(connection);
                        continue;
                    }
                }

                Thread.Sleep(1000);
            }
        }
        public static void Disconnect(ClientConnection clientConnection, int reason)
        {
            if (clientConnection.State == ClientConnectionState.LOGGED)
            {
                if (reason != 0)
                {
                    DisconnectedMessage disconnectedMessage = new DisconnectedMessage();
                    disconnectedMessage.SetReason(reason);
                    clientConnection.Messaging.Send(disconnectedMessage);
                }
                else
                {
                    TcpServerSocket.Disconnect(clientConnection);
                }
            }

            clientConnection.SetState(ClientConnectionState.DISCONNECTED);
        }