Beispiel #1
0
 /// <summary>
 /// Принятое событие от сервера
 /// </summary>
 /// <param name="Command">Объект команды</param>
 private void ServerAction(FromServerCommand Command)
 {
     if (ServerReceiveCommand != null)
     {
         ServerReceiveCommand(Command);
     }
 }
Beispiel #2
0
        void client_ServerReceiveCommand(FromServerCommand Command)
        {
            if (Command.Action == ServerActions.ConnectionFailed)
            {
                proxyServer.Send(new ToServerCommand()
                {
                    Action = ServerCommands.Disconnect, ToClient = new List <OnServerClientConnection> {
                        (OnServerClientConnection)Command.UserToken
                    }
                });
            }
            if (Command.Action == ServerActions.Receive)
            {
                proxyServer.Send(new ToServerCommand()
                {
                    Action = ServerCommands.Send, ReceiveBuffer = Command.ReceiveBuffer, ToClient = new List <OnServerClientConnection> {
                        (OnServerClientConnection)Command.UserToken
                    }
                });
            }
            if (Command.Action == ServerActions.Disconnected)
            {
                proxyServer.Send(new ToServerCommand()
                {
                    Action = ServerCommands.Disconnect, ToClient = new List <OnServerClientConnection> {
                        (OnServerClientConnection)Command.UserToken
                    }
                });
            }

            if (Command.Action != ServerActions.ConnectionFailed && Command.Action != ServerActions.Receive && Command.Action != ServerActions.Connecting && Command.Action != ServerActions.Connected && Command.Action != ServerActions.Disconnected)
            {
            }
        }
Beispiel #3
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;
            }
        }
Beispiel #4
0
 private void OpenInternal(FromServerCommand Command)
 {
     if (ServerReceiveCommand != null)
     {
         // выполняется в основном потоке
         SendOrPostCallback cb = state => ServerReceiveCommand(Command);
         _AsyncOperation.Post(cb, null);
     }
 }
Beispiel #5
0
        void client_ServerReceiveCommand(FromServerCommand Command)
        {
            if (Command.Action == ServerActions.SendCompleted || Command.Action == ServerActions.Connected)
            {
                TB_MessageField.IsEnabled = true;
            }

            if (Command.ReceiveBuffer == null)
            {
                TB_Messages.AppendText(DateTime.Now.ToString("HH:mm:ss.f") + " Message: " + Command.Action + "\n");
            }
            else
            {
                TB_Messages.AppendText(DateTime.Now.ToString("HH:mm:ss.f") + " Message: " + Command.Action + ", Buffer: " + Encoding.UTF8.GetString(Command.ReceiveBuffer, 0, Command.ReceiveBufferLength) + "\n");
            }
            TB_Messages.ScrollToEnd();
        }
Beispiel #6
0
        void ClientModule_ServerReceiveCommand(FromServerCommand Command)
        {
            if (Command.Action == ServerActions.AlreadyConnected)
            {
                TB_Messages.AppendText(Command.UserToken.ToString() + " Message: " + Command.Action + "\n");
            }
            else if (Command.Action == ServerActions.Connected)
            {
                TB_Messages.AppendText(Command.UserToken.ToString() + " Message: " + Command.Action + "\n");
            }
            else if (Command.Action == ServerActions.ConnectedOverProxy)
            {
                TB_Messages.AppendText(Command.UserToken.ToString() + " Message: " + Command.Action + "\n");
            }
            else if (Command.Action == ServerActions.ConnectedToProxy)
            {
                TB_Messages.AppendText(Command.UserToken.ToString() + " Message: " + Command.Action + "\n");
            }
            else if (Command.Action == ServerActions.Connecting)
            {
                TB_Messages.AppendText(Command.UserToken.ToString() + " Message: " + Command.Action + "\n");
            }
            else if (Command.Action == ServerActions.ConnectingToProxy)
            {
                TB_Messages.AppendText(Command.UserToken.ToString() + " Message: " + Command.Action + "\n");
            }
            else if (Command.Action == ServerActions.ConnectionFailed)
            {
                TB_Messages.AppendText(Command.UserToken.ToString() + " Message: " + Command.Action + "\n");
            }
            else if (Command.Action == ServerActions.Disconnected)
            {
                try
                {
                    TB_Messages.AppendText(Command.UserToken.ToString() + " Message: " + Command.Action + "\n");
                    ServerModule.Send(new ToServerCommand()
                    {
                        Action = ServerCommands.Disconnect, ToClient = new List <OnServerClientConnection>()
                        {
                            ((OnServerClientConnection)Clients[(EndPoint)Command.UserToken][0])
                        }
                    });
                }
                catch { }
            }
            else if (Command.Action == ServerActions.ProxyAuthFailed)
            {
                TB_Messages.AppendText(Command.UserToken.ToString() + " Message: " + Command.Action + "\n");
            }
            else if (Command.Action == ServerActions.Receive)
            {
                byte[] buf = new byte[Command.ReceiveBufferLength];
                Array.Copy(Command.ReceiveBuffer, 0, buf, 0, Command.ReceiveBufferLength);

                try
                {
                    ServerModule.Send(new ToServerCommand()
                    {
                        Action = ServerCommands.Send, ReceiveBuffer = buf, ToClient = new List <OnServerClientConnection>()
                        {
                            ((OnServerClientConnection)Clients[(EndPoint)Command.UserToken][0])
                        }
                    });
                }
                catch { }
                TB_Messages.AppendText(Command.UserToken.ToString() + " Message: " + Command.Action + "\n");
            }
            else if (Command.Action == ServerActions.SendCompleted)
            {
                TB_Messages.AppendText(Command.UserToken.ToString() + " Message: " + Command.Action + "\n");
            }
            else if (Command.Action == ServerActions.Shutdown)
            {
                TB_Messages.AppendText(Command.UserToken.ToString() + " Message: " + Command.Action + "\n");
            }
        }