Beispiel #1
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);
        }
Beispiel #2
0
 public static void ExitProgram()
 {
     MyTcpClient.KillClient();
 }