EMX Socket.Connect timeout

I have been searching the forum for an answer, but could not find it.

I use the below code to connect to a server on the internet. Hardware is EMX.

    private static Socket ConnectSocket(String IpAddress, Int32 port)

      Socket socket = new Socket(AddressFamily.InterNetwork,  SocketType.Stream, ProtocolType.Tcp);
      IPAddress Address = IPAddress.Parse(IpAddress);     
      socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
      socket.Connect(new IPEndPoint(Address, port));
      return socket;

This works fine, unless I take out the ethernet cable. In that case, the Socket.connect call hangs forever.
I have googled a bit about this and it seems I’m not the only one who has experienced this behaviour. However, if I understand correct, this should be fixed in version 4.2 of the SDK.

This leeds me to two questions:

  1. Is there a way around this in 4.1?
  2. Could I upgrade EMX to 4.2 at this time? As far as I can tell, it’s not completely ready for EMX right?


I think users have use a thread to handle networking, which is terminated to work around this.

Hi Gus,

Thanks for the fast reply. I have read about this as wel, but I have also read that this call blocks all threads. I did not test this myself, so I’m not sure.
I read about this on Socket.Connect blocks all threads? - Netduino Plus 2 (and Netduino Plus 1) - Netduino Forums

As far as I know, only DHCP blocks all threads.

Upgrading to 4.2 is not recomended or possible for EMX?

Anyone has a small sample on this aproach?

Of course it is possible. 4.2 has a complete different TCP/IP stack and things should be better. The only problem here is that 4.2 is a release candidate still and new stack could mean little problems here and there. We are fully concentrating on this.

By the way, 4.2 handles your cable events very nicely. See this please http://www.tinyclr.com/codeshare/entry/588

Thanks Gus, I will give 4.2 a try.
I was a bit confused after reading this info from the NetMF 4.1 to 4.2 Wiki:

Now, for the answer! We now have a little problem, 4.1 is complete but not all module drivers were built for 4.1 so they are only available in 4.2. To add more confusion, our gadgeteer SDK installs 4.1 and 4.2 currently! This will be all resolved and 4.2 is the answer in few weeks but till then here is what you need ot know:

  1. If you are using a System-on-Module (USBizi, EMX, ChipworkX) then keep on using 4.1
  2. If you are a gadgeteer user and need WiFi then keep on using 4.1
  3. If you are gadgeteer user and do not need WiFi then 4.2 beta is recommended

That’s why I assumed not to use 4.2.

Wiki is not always up to date. We are always here to clarify any points.

Latest release with networking was only few days ago.

Thanks! I will see how things go with 4.2.

Meanwhile, I’ll leave the question unanswered to see if anyone comes up with workaround code sample for 4.1

Have a nice weekend!