Trouble with HTTP CLIENT SAMPLE CODE FOR FEZ CONNECT

Hi.

Did anybody try “HTTP CLIENT SAMPLE CODE FOR FEZ CONNECT” of Code section?

I am experimenting many troubles since it always raises me :

Message: Timeout occurs during connection establishment

#### GHIElectronics.NETMF.Net.SocketNative::connect [IP: 0135] ####
#### GHIElectronics.NETMF.Net.Sockets.Socket::Connect [IP: 002c] ####

on following line:

resp = request.GetResponse();

Even more, it happens also when I simply do:


IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse("192.168.0.125"), 80);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Tcp);
socket.Connect(remoteEndPoint);

…where 192.168.0.125 is on same subnet of W5100.

I am working with a DFRobots ethernet shield modded as suggested by Gus.

Any hints?

What kind of device is 192.168.0.125 ?

Did you look at what’s happening with a protocol analyser like Wireshark ?

please show your code for the initialization of the w5100 interface.

Mike:


public static void Main()
        {

            byte[] ip = { 192, 168, 0, 3 };
            byte[] subnet = { 255, 255, 255, 0 };
            byte[] gateway = { 192, 168, 0, 252 };
            byte[] mac = { 43, 185, 44, 3, 206, 129 };
            WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di9, true);
            NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
            NetworkInterface.EnableStaticDns(new byte[] { 192, 168, 0, 120 });

            Debug.Print("Network settings:");
            Debug.Print("IP Address: " + new IPAddress(NetworkInterface.IPAddress).ToString());
            Debug.Print("Subnet Mask: " + new IPAddress(NetworkInterface.SubnetMask).ToString());
            Debug.Print("Default Getway: " + new IPAddress(NetworkInterface.GatewayAddress).ToString());
            Debug.Print("DNS Server: " + new IPAddress(NetworkInterface.DnsServer).ToString());
            // Print the HTTP data from each of the following pages.

            TestConnect();

            PrintHttpData("http://192.168.0.125/iisstart.htm");
            
        }

        static void TestConnect()
        {
            IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse("192.168.0.142"), 80);
            
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Tcp);

            socket.Connect(remoteEndPoint);
            
            Debug.Print("Connect: Connected");
        }

Nicolas3:

No, I’ll try.

Wouter:

It is a windows server 2008 box, with IIS default site.

 Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Tcp);

TCP requires a SocketType of Stream not Dgram which is used with UDP.

 Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

I tried with Stream, also, but without success.

And what about HttpClient malfunctioning? It uses Socket in stream mode under the hood…or am I wrong?

Can it be the remote host (windows server 2008 ) is refusing the connection?

You’re talking about connecting to .125 but in your code it shows .142

So you have a gateway at .252, a DNS server at .120 and a HTTP server at .142

Seems like a complex network situation to start with :slight_smile:

The Connect() test is trying to reach another host but just for testing purposes.

What I would like to know is whether anybody did ever succeed in doing an Http client request using W5100 chip and new “stack” released with latest SDK.

Since socket.Connect() timeout isn’t settable, could it be too short for some networks?

If you start with a very simple test setup, you will be able to answer the question yourself. If that doesn’t work, then others can help by repeating and analyzing the simple setup.

My setup is very simple:

[quote]So you have a gateway at .252, a DNS server at .120 and a HTTP server at .142
Seems like a complex network situation to start with Smiley[/quote]
I meant the complex setup. Put everything on one network to see if it works at all. Then move to more complex configurations. It’s easier to find problems when there are not so many variables.

another test - once you’ve initialised the Wiz chip, can you PING it’s IP address? And is that MAC address one you made up ? Find your PC’s MAC and change the last two octets and use that, see if it helps (oh gee how I wish Wiz would have provided a valid/registered MAC range that we could use)

Or add a cheap chip with valid address that can be read out:
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en538613

if you’re doing a custom board or something, yeah sure. Just a bit of overkill if you have a shield and are plugging it into a Fez (or xDuino).

Thanks Brett!

You saved my day!

Despite I could ping the device, HttpClient calls started to work only when I changed MAC address to replicate the one of my PC with last 2 byte changed.

I have just 2 questions:

  1. How can you explain such behavior?
  2. Why did you know that ;D

Thanks again!

there was a similar post a week or two ago :). It seems like some switches don’t handle totally made up MAC addresses or certain address ranges. The switch probably discards the traffic as invalid, so that it never gets to the fez.

Most switches and routers will have a problem if the first octet of the mac address is “ODD” or has the least significant bit set to “1”. This is used to indicate a MAC Multi cast. see MAC address - Wikipedia .

Here is the tool I use to create “Safe” mac addresses. http://www.macvendorlookup.com/ as long as you are on you own lan segment you can use any of the addresses it generates, just DON’T use the same MAC on other devices on the same LAN segment. ;D

Dave, Thank you for the very useful information.
I updated the MAC address in the code example with ones generated by this tool.