Infinit Network Sockets in Spider 4.2.11.0

Hello guys,
following up to my other Post about the limit of 2 Sockets in Cerbuino, I decided to test the spider and see what it reports… and the results are not realistic…

I ran the following test:



            var SCount = 1;

            while (true)
            {
                Thread.Sleep(10);
                try
                {
                    var jayc = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                    Debug.Print("********** Socket Test " + SCount++ + " **********");
                    Thread.Sleep(10);
                }
                catch (ConstraintException)
                {
                    Debug.Print("********** Constaint Exception on Test " + SCount + " **********");
                }

            }

and got the following results well I had to stop it…otherwise it would have continued for ever…



********** Socket Test 1 **********
********** Socket Test 2 **********
********** Socket Test 3 **********
********** Socket Test 4 **********
********** Socket Test 5 **********
********** Socket Test 6 **********
********** Socket Test 7 **********
********** Socket Test 8 **********
********** Socket Test 9 **********
.
.
.
.
.
.
********** Socket Test 658 **********
********** Socket Test 659 **********
********** Socket Test 660 **********
********** Socket Test 661 **********
********** Socket Test 662 **********
********** Socket Test 663 **********
********** Socket Test 664 **********
********** Socket Test 665 **********
********** Socket Test 666 **********
********** Socket Test 667 **********
********** Socket Test 668 **********
********** Socket Test 669 **********
********** Socket Test 670 **********
********** Socket Test 671 **********
********** Socket Test 672 **********
********** Socket Test 673 **********
********** Socket Test 674 **********
********** Socket Test 675 **********
********** Socket Test 676 **********
********** Socket Test 677 **********
********** Socket Test 678 **********
********** Socket Test 679 **********
********** Socket Test 680 **********

so 680 sockets and still counting seems a bit high where I know the spider had somewhere 128 sockets that somehow got trimmed down to 32 …

so what is going on???

Every iteration of your loop previous socket goes out of scope and it is GC collected, which also frees the native socket handle.

Declare an array of 512 socket for example outside of while loop and try to create 512 of them.

i wondered about that but for some reason is it fails on a cerbuino and give me only two sockets… same code…

You can’t predict when GC runs

Ok,
SO i modified the code to the following:


         ArrayList jayc = new ArrayList();

            var SCount = 1;

            while (true)
            {
                Thread.Sleep(10);
                try
                {
                   jayc.Add(new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp));
                    Debug.Print("********** Socket Test " + SCount++ + " **********");
                    Thread.Sleep(10);
                }
                catch (Exception)
                {
                    Debug.Print("********** Constaint Exception on Test " + SCount + " **********" + jayc.Count);
                }

            }

and i get the following results:


********** Socket Test 1 **********
********** Socket Test 2 **********
********** Socket Test 3 **********
********** Socket Test 4 **********
********** Socket Test 5 **********
********** Socket Test 6 **********
********** Socket Test 7 **********
********** Socket Test 8 **********
********** Socket Test 9 **********
********** Socket Test 10 **********
********** Socket Test 11 **********
********** Socket Test 12 **********
********** Socket Test 13 **********
********** Socket Test 14 **********
    #### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (5) ####
    #### Message: 
    #### Microsoft.SPOT.Net.SocketNative::socket [IP: 0000] ####
    #### System.Net.Sockets.Socket::.ctor [IP: 001f] ####
    #### UPNPTEST.Program::Interface_NetworkAddressChanged [IP: 00c3] ####
    #### GHI.Premium.Net.NetworkInterfaceExtension::NetworkChangeExtension_NetworkAddressChanged [IP: 0021] ####
    #### GHI.Premium.Net.NetworkChangeExtension::OnNetworkChangeCallback [IP: 00ac] ####
    #### GHI.Premium.Net.NetworkChangeExtension+NetworkChangeExtensionListener::OnEvent [IP: 000d] ####
    #### Microsoft.SPOT.EventSink::EventDispatchCallback [IP: 0014] ####
    #### SocketException ErrorCode = 10055
    #### SocketException ErrorCode = 10055
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll
    #### SocketException ErrorCode = 10055
An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll

so now instead of the 128 sockets that were available on 4.1 it went down to 32 on 4.2 to 14 on 4.2 R2… i mean what is really going on…???

I don’t know anymore. :frowning:

Edit:

Is it consistent 14 every time you run it?

Yep…

It’s a nasty bug…

Man we really have to get these networking issues hammered once and for all…

I mean really GHI… every board seems to have one issue or another in the networking…

Spider. Used to be 128 socket s,now 14
Cerbuino, i suspect all curb family has the same issue. 2 sockets available. Less than Mountaineer and usbizi
Mountaineer: listening on udp broadcast doesn’t work.

Plus all the hanging and freezing issues others have reported with the other boards, G120, G400…

Can we tackle these issues once and for all, and call these IoT …

Please…

2 Likes

Socket count is low and reported already. Please vote http://netmf.codeplex.com/workitem/1907

What are the other issues?

@ Jay Jay - Interesting. Can you repeat your test, but try to creat a different type of socket?

unrelated to my issue really since i can’t even get the reported 32 sockets on the Spider… so something is definitely wrong with the current firmware.

same goes for my other post about the cerbuino. limit to 2 sockets…

thanks, I hope to hear of a resolution soon…

i’ll be happy to beta test any new firmware since what i’m working on usually brings out these bugs easily…

thanks.
Jay.

32 is the limit to all sockets. Maybe UDP is set to 14. Have you tried to open a TCP socket? I am not arguing here but we are listening and working very hard to cover any concerns. Stay tuned for updates.

ok here are some interesting results:

usingthe following code:


       
            ArrayList jayc = new ArrayList();

            var SCount = 1;
     
            while (true)
            {
                try
                {
                    jayc.Add(new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp));
                    Debug.Print("**********UDP Socket Test " + SCount++ + " **********");
                }
                catch (Exception)
                {
                    Debug.Print("**********UDP Exception on Test " + SCount + " **********" + jayc.Count);
                    break;
                }

                Thread.Sleep(100);
            }

            SCount = 1;
            while (true)
            {
                Thread.Sleep(10);
                try
                {
                    jayc.Add(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp));

                    Debug.Print("**********TCP Socket Test " + SCount++ + " **********");
                    Thread.Sleep(10);
                }
                catch (Exception)
                {
                    Debug.Print("********** TCP Exception on Test " + SCount + " **********" + jayc.Count);
                    break;
                }

            }

I get the following results:

the MountaineerEth gives us 4 UDP and 5 TCP


**********UDP Socket Test 1 **********
**********UDP Socket Test 2 **********
**********UDP Socket Test 3 **********
**********UDP Socket Test 4 **********
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll
**********UDP Exception on Test 5 **********4
**********TCP Socket Test 1 **********
**********TCP Socket Test 2 **********
**********TCP Socket Test 3 **********
**********TCP Socket Test 4 **********
**********TCP Socket Test 5 **********
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll

the Cerbuino gives us 2 UDP Sockets and 5 TCP


**********UDP Socket Test 1 **********
**********UDP Socket Test 2 **********
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll
**********UDP Exception on Test 3 **********2
**********TCP Socket Test 1 **********
**********TCP Socket Test 2 **********
**********TCP Socket Test 3 **********
**********TCP Socket Test 4 **********
**********TCP Socket Test 5 **********
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll

The Spider gives us: 14 UDP Sockets and 25 TCP Sockets a total of 39 Sockets. despite the 32 limit you mentioned :(, if I don’t open UDP I get 39 TCP total… but only 14 total even if no TCP are open.


**********UDP Socket Test 1 **********
**********UDP Socket Test 2 **********
**********UDP Socket Test 3 **********
**********UDP Socket Test 4 **********
**********UDP Socket Test 5 **********
**********UDP Socket Test 6 **********
**********UDP Socket Test 7 **********
**********UDP Socket Test 8 **********
**********UDP Socket Test 9 **********
**********UDP Socket Test 10 **********
**********UDP Socket Test 11 **********
**********UDP Socket Test 12 **********
**********UDP Socket Test 13 **********
**********UDP Socket Test 14 **********
    #### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (5) ####
    #### Message: 
    #### Microsoft.SPOT.Net.SocketNative::socket [IP: 0000] ####
    #### System.Net.Sockets.Socket::.ctor [IP: 001f] ####
    #### UPNPTEST.Program::Interface_NetworkAddressChanged [IP: 00bc] ####
    #### GHI.Premium.Net.NetworkInterfaceExtension::NetworkChangeExtension_NetworkAddressChanged [IP: 0021] ####
    #### GHI.Premium.Net.NetworkChangeExtension::OnNetworkChangeCallback [IP: 00ac] ####
    #### GHI.Premium.Net.NetworkChangeExtension+NetworkChangeExtensionListener::OnEvent [IP: 000d] ####
    #### Microsoft.SPOT.EventSink::EventDispatchCallback [IP: 0014] ####
    #### SocketException ErrorCode = 10055
    #### SocketException ErrorCode = 10055
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll
    #### SocketException ErrorCode = 10055
    #### SocketException ErrorCode = 10055
**********UDP Exception on Test 15 **********14
**********TCP Socket Test 1 **********
**********TCP Socket Test 2 **********
**********TCP Socket Test 3 **********
**********TCP Socket Test 4 **********
**********TCP Socket Test 5 **********
**********TCP Socket Test 6 **********
**********TCP Socket Test 7 **********
**********TCP Socket Test 8 **********
**********TCP Socket Test 9 **********
**********TCP Socket Test 10 **********
**********TCP Socket Test 11 **********
**********TCP Socket Test 12 **********
**********TCP Socket Test 13 **********
**********TCP Socket Test 14 **********
**********TCP Socket Test 15 **********
**********TCP Socket Test 16 **********
**********TCP Socket Test 17 **********
**********TCP Socket Test 18 **********
**********TCP Socket Test 19 **********
**********TCP Socket Test 20 **********
**********TCP Socket Test 21 **********
**********TCP Socket Test 22 **********
**********TCP Socket Test 23 **********
**********TCP Socket Test 24 **********
**********TCP Socket Test 25 **********
    #### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (5) ####
    #### Message: 
    #### Microsoft.SPOT.Net.SocketNative::socket [IP: 0000] ####
    #### System.Net.Sockets.Socket::.ctor [IP: 001f] ####
    #### UPNPTEST.Program::Interface_NetworkAddressChanged [IP: 0127] ####
    #### GHI.Premium.Net.NetworkInterfaceExtension::NetworkChangeExtension_NetworkAddressChanged [IP: 0021] ####
    #### GHI.Premium.Net.NetworkChangeExtension::OnNetworkChangeCallback [IP: 00ac] ####
    #### GHI.Premium.Net.NetworkChangeExtension+NetworkChangeExtensionListener::OnEvent [IP: 000d] ####
    #### Microsoft.SPOT.EventSink::EventDispatchCallback [IP: 0014] ####
    #### SocketException ErrorCode = 0
    #### SocketException ErrorCode = 0
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll
    #### SocketException ErrorCode = 0
    #### SocketException ErrorCode = 0
********** TCP Exception on Test 26 **********39

so as you can see something is not right…

So it looks like it somewhat consistent with the Gus’s description of the issue on codeplex. Let’s hope MS will address it one way or another.

Just curious what is you application and where do you run into these limits besides the test?

I find it hard to believe that the 32 limit is in NETMF because the Spider gives 39 sockets… and the last test I just ran using the Emulator gave me 62 Total sockets… so at least this tells us that the limit set by the framework is 62 and not 32.

[Quote]
Just curious what is you application and where do you run into these limits besides the test?[/Quote]

I’ve created a UPnP Stack and been waiting on these issues to be fixed so I can release it… but keep hitting walls every time…

the stack is optimized to be used on small devices but it requires at least 4 Free Sockets…

which is what the cerb family was giving us in 4.1… 1 reserved for DHCP and 4 Available …

the stacks works great on a spider (39 is way beyond what I need, I just mentioned it here because I found it odd to have gone from 128 in 4.1 to 39 or 32 or whatever it is now), as of now my spider can talk to any other UPnP device on the network meaning another spider, Hydra, PC Tablet and so on… so far the broadcasting issues with the Mountaineer must be fixed so it can too play, because it can be seen but can’t see others, and the cerbuino well that one is out of the game until I get my 4 sockets back…

the stack requires 3 UDP and 1 or 2 TCP…

Cheers,
Jay.

@ Jay Jay - what your see on emulator is not related to the framework, which uses a different network stack.

There are over 10 defines to the network limits. I invite you to take a look at the source code to learn more about the socket limits.

We have done some work with networking in the SDK released today. You should be able to create more sockets now. On Cerberus, in all of our tests, we were able to make 6 TCP sockets and 5 UDP sockets.

2 Likes

@ andre.m - Yep!

https://www.ghielectronics.com/support/netmf/sdks