views:

45

answers:

1
//code in the client
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://192.168.0.5/test");
WebResponse response = request.GetResponse();

I have a LAN setup with two machines in my workgroup. - 192.168.0.1 (that's the client) - 192.168.0.5 (that's the web server)

The above piece of code works perfectly fine in a simple wired network.

When I run it on a wireless network, i.e. with the network setup using a wi-fi router instead of a switch, the code doesn't work - it gets stuck on GetResponse.

Strangely, when I open up my browser and type - http://192.168.0.5/test - it works...the page shows up!

What am I missing? Why is the client not able to contact the server through code?

+2  A: 

By "gets stuck" do you mean it hangs?

Is this the first request in the program, or are there others? One frequent cause of "hanging" web requests is failure to close/dispose web responses. Once you've made two (by default) requests to the same server, you'd have to wait for the responses to be finalized.

I don't know why this would only affect you in the case of a wireless network connection instead of wired, but if you're not closing web responses (preferably with using statements) I'd recommend fixing that to start with.

Next up, trace the network with WireShark. That should make it really easy to see whether the request is actually sent, whether a response comes back etc.

Jon Skeet
Thank you for replying sir.By "gets stuck" , I do mean it hangs - eventually moves to the catch block with the timeout exception.This is the first request that the client sends, so no question of unclosed web responses.I will try Wireshark and see if it helps. Thanks.
SaM
Righto. If it does make the request but doesn't get a response back, I'd compare the request from .NET with the request from the browser. I don't expect it'll be fun looking at it in a huge amount of detail, but it should help eventually.
Jon Skeet