Socket.Connect Hangs

This will hang forever (Hydra 4.2); replace X.X.X.X with any IP on your network that is not allocated.

            _conn = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _conn.ReceiveTimeout = 2000;
            _conn.Connect(new IPEndPoint(IPAddress.Parse("X.X.X.X"), port));

I would expect at some point it to throw an error or timeout or something. It never does. The only time this code will exit is when something becomes available at the IP address. And then, the thread will exit.

Is there a way around this?

In full framework the try will result in a catch of “Target Machine Actively Refused Connection”, nothing comes of it on NETMF

I would bring this up to netmf codeplex.

So this is a confirmed issue w the framework? Not just something I’m doing wrong, etc?

No we having tested it just yet but I can’t see how would this be related to a specific port.

Please up vote: http://netmf.codeplex.com/workitem/1830

With the full framework, this only occurs if there is a host at the IP address and it refuses the call.

And if not it will timeout in full framework. Neither of these seen to occur in MF. Anyone who wants to double check is more than welcome :slight_smile:

How long have you been waiting for the timeout? It takes a long time 20-30+ seconds

I believe I waited well past that mark, but I will double-check tonight. I’ll also check with a completely invalid IP on my network and see if it’s only on active refusal or non-existence as well.