Beispiel #1
0
 protected override void OnFormClosing(FormClosingEventArgs e)
 {
     if (connected)
     {
         timer.Change(Timeout.Infinite, 0);
         lock (io)
         {
             io.WriteLine("QUIT");
             io.ReadLine(); //Eat the OK
             io.Disconnect();
             timer.Dispose();
         }
         connected = false;
     }
     //((Houston)Owner).rjo = null;
 }
Beispiel #2
0
 public void Disconnect()
 {
     // First close the sec. server
     if (io2 != null)
     {
         lock (io2)
         {
             io2.locker++;
             io2.WriteLine("QUIT");
             io2.ReadLine(); //Eat the OK
             io2.Disconnect();
             io2.locker--;
         }
     }
     //Then the primary
     lock (io)
     {
         io.locker++;
         io.WriteLine("QUIT");
         io.ReadLine(); //Eat the OK
         io.Disconnect();
         io.locker--;
     }
 }
Beispiel #3
0
    private void ClientConnect()
    {
        string image;

        IPAddress rwhodip = getrwhodserver();

        if (rwhodip == IPAddress.None)
        {
            return;
        }

        SetStatusBarText("Connecting to server...");
        io = new ServerIO();
        try
        {
            if (io.Connect(rwhodip.ToString(), 7040))
            {
                SetStatusBarText("Connected to the server.");

                if ((image = io.ReadLine()) != null)
                {
                    if (image.Substring(0, 1) == "+")
                    {
                        io.WriteLine("MODE ruptime");
                        image = io.ReadLine();
                        if (image.Substring(0, 1) == "+")
                        {
                            connected = true;
                            timer.Change(500, 0);
                        }
                        else
                        {
                            SetStatusBarText("The server doesnot support this feature.");

                            io.WriteLine("QUIT");
                            io.ReadLine(); //Eat the OK
                            io.Disconnect();
                        }
                    }
                    else
                    {
                        SetStatusBarText("Bad response from server: " + image.Substring(5));

                        io.WriteLine("QUIT");
                        io.ReadLine(); //Eat the OK
                        io.Disconnect();
                    }
                }
                else
                {
                    SetStatusBarText("Bad response from server.");
                    io.Disconnect();
                    Thread.Sleep(1000);
                    SetStatusBarText("Disconnected.");
                }
            }
            else
            {
                SetStatusBarText("No response from server: host not found");
            }
        }
        catch (Exception e)
        {
            SetStatusBarText("No response from server: " + e.Message);
        }
    }