Question

//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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top