client server connection check

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cherryblossom
    New Member
    • Mar 2008
    • 3

    client server connection check

    hii

    im developing a client server connection.

    i have a set of servers..

    and i connect the client to one of these servers using the following code

    Code:
    using System;
    using System.IO;
    using System.Net.Sockets;
    using System.Diagnostics;
    using System.Threading;
    using System.Net;
    
    class EmployeeTCPClient
    {
        public static TcpClient client;
        public static string[] ipsrvr;
        public static int m = 0;
        //public static IPAddress[] ipsrvr;
        [STAThread]
        public static void Main(string[] args)
        {
            ipsrvr = new string[4];
            //ipsrvr = new IPAddress[4];
            ipsrvr[0] = "1.2.3.4";
            
            ipsrvr[1] = "55.6.7.80";
            ipsrvr[2] = "23.45.67.89";
            ipsrvr[3] = "34.56.78.98";
    
            sconnect(ipsrvr[m]);
            
            Console.ReadLine();
    
        }
        public static void sconnect(string id)
        {
            
            client = new TcpClient(id,8080);
            
    
            if (client.Connected)
            {
                Console.WriteLine("Connected to Server");
                
            }
            else
            {
                m++;
                if (m > 3)
                {
                    Console.WriteLine("All servers are down");
                }
                else
                {
                    sconnect(ipsrvr[m]);
                }
    
            }
            
    
        }
    the problem is even if all the servers are down. the client.connecte d returns the value true...it does not go to the else part... and displays Connected to server...y is this happpening.

    how to check that the client is connected to server or not.
Working...