Example #1
0
        /// <summary>
        /// Внутренняя обработка списка подключенных клиентов
        /// </summary>
        /// <param name="Command">Входящее сообщение от килента</param>
        private void ServerConnection_ServerReceiveCommand(FromServerCommand Command)
        {
            if ((Command.Action == ServerActions.Disconnected || Command.Action == ServerActions.ConnectionFailed) && localDisconnect)
            {
                localDisconnect = false;

                Sock.Close();
                //Sock.Dispose();

                Sock = CreateSocket();
            }

            OpenInternal(Command);
            switch (Command.Action)
            {
            case ServerActions.Connected:
            case ServerActions.ConnectedToProxy:
                isConnected = true;
                break;

            case ServerActions.ConnectionFailed:
            case ServerActions.Disconnected:
            case ServerActions.ProxyAuthFailed:
            case ServerActions.Shutdown:
                isConnected      = false;
                ClientConnection = null;
                break;

            default:
                break;
            }
        }
Example #2
0
        private void ProcessConnect(SocketAsyncEventArgs e)
        {
            if (e.SocketError == SocketError.Success)
            {
                //ClientConnection = new OnClientConnection(e.ConnectSocket, m_ProxyUse, m_OnConnectBuffer, m_ReceiveBufferSize, e.UserToken);
                ClientConnection = new OnClientConnection(e.AcceptSocket, m_ProxyUse, m_OnConnectBuffer, m_ReceiveBufferSize, e.UserToken);

                if (m_ProxyUse)
                {
                    ServerConnection_ServerReceiveCommand(new FromServerCommand()
                    {
                        Action = ServerActions.ConnectedToProxy, UserToken = e.UserToken
                    });
                }
                else
                {
                    ServerConnection_ServerReceiveCommand(new FromServerCommand()
                    {
                        Action = ServerActions.Connected, UserToken = e.UserToken
                    });
                }
            }
            else
            {
                ServerConnection_ServerReceiveCommand(new FromServerCommand()
                {
                    Action = ServerActions.ConnectionFailed, ReceiveBuffer = System.Text.Encoding.ASCII.GetBytes(e.SocketError.ToString()), ReceiveBufferLength = e.SocketError.ToString().Length, UserToken = e.UserToken
                });
                //OpenInternal(new FromServerCommand() { Action = FromServerCommand.Actions.ConnectionFailed, ReceiveBuffer = System.Text.Encoding.ASCII.GetBytes(e.SocketError.ToString()), ReceiveBufferLength = e.SocketError.ToString().Length });
            }
            localBlockConnect = false;
        }