Beispiel #1
0
        public String RunBackground()
        {
            NetworkStream stream = MyTcpClient.InitializeConnection(null, null);

            if (stream == null)
            {
                return("Could not connect to the default server");
            }
            if (!_commandsQueueThread.IsAlive)
            {
                _commandsQueueThread.Start();
            }

            Thread clientThread = new Thread(() => MyTcpClient.CreateAndRunClient(stream));

            clientThread.Start();
            return(null);
        }
Beispiel #2
0
        public string SwitchServer(string ip, string port)
        {
            string reply = String.Empty;

            if (String.IsNullOrEmpty(ip) || String.IsNullOrEmpty(port))
            {
                reply = "Invalid IP or Port inserted";
                ThrowNewError(reply);
                return(reply);
            }
            NetworkStream stream = MyTcpClient.InitializeConnection(ip, port);

            if (stream == null)
            {
                reply = "Could not connect to the given IP and Port";
                ThrowNewError(reply);
                return(reply);
            }
            else
            {
                if (!_commandsQueueThread.IsAlive)
                {
                    _commandsQueueThread.Start();
                }

                if (MyTcpClient.ThreadAlreadyRunning)
                {
                    MyTcpClient.KillClient();
                }
                MyTcpClient.M.WaitOne();
                Thread clientThread = new Thread(() => MyTcpClient.CreateAndRunClient(stream));
                clientThread.Start();
                MyTcpClient.ThreadAlreadyRunning = true;
                reply = "Connected succefully to the new server";
            }
            return(reply);
        }