George George

George George

  • NA
  • 778
  • 0

strange Http timeout issue

Jan 19 2009 5:14 AM

Hello everyone,

I met with timeout issue. Here is my whole code. I just send Http request to two local LAN servers and see if response could be received in given time, then I treat the server as healthy, or else I will treat them as unhealthy.

The two servers are simple ASP.Net ASMX Web Serviers Web Servers on IIS. The timeout will happen for both servers are PingServers method executing for 4-5 times successfully. It is strange timeout since the server are pretty fast -- I use IE to access the same URL, it takes less than 1 second to return, but in my code, I set timeout to be 4 seconds, it will prints timeout.

Does anyone have any ideas? Any bugs in my code?

[Code]

       static void PingServers(Object state)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create((String)state);
            request.Timeout = 4 * 1000;
            HttpWebResponse response = null;
            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException ex)
            {
                Console.WriteLine((String)state + " " + ex.ToString());
                return;
            }

            Console.WriteLine((String)state + " is healthy");

            return;
        }

        static Timer[] monitorTimers = new Timer[2];
       
        static void Main(string[] args)
        {
            monitorTimers[0] = new Timer(PingServers, "http://localserver1/test/test.ashx", 0, 10 * 1000);
            monitorTimers[1] = new Timer(PingServers, "http://localserver2/test/test.ashx", 0, 10 * 1000);

            Console.ReadLine();

            return;
        }
[/Code]

thanks in advance,
George