void ethernet_J11D_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
ipAddress = ethernet_J11D.NetworkSettings.IPAddress;
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
System.Net.IPAddress ipaddressReady = System.Net.IPAddress.Parse(ipAddress);
System.Net.IPEndPoint localEndPoint = new System.Net.IPEndPoint(ipaddressReady, port);
Socket clientSocket = server.Accept();
// Process the client request. true means asynchronous.
new ProcessClientRequest(clientSocket, true);
catch (System.Net.Sockets.SocketException e)
Everything works fine but sometimes the while true loop got stuck somehow and my gadgeteer won’t accept new connections. I’m trying to connect to the gadgeteer via sockets, I ran it on Visual studio 2010 and sometimes nothing happened. I decided to put a breaking point (while the program was running) on the while (true) line, Then it became yellow which means that the loop got stuck, I pressed play (to jump to the next command) and suddenly new connection was accepted.
There is a strange issue with NETMF (not sure if GHI related or not), when a debug session is open.
The program suddenly stops as if it ran on a break point.
If you press pause, and then continue in VS, the program runs again.
This does usually not happen on very simple projects. But as soon as a projects gets more complex (Networking, Threads, …) it happens more often.
If no debugger is attached, the program runs just fine without any issues.
And as Mike already posted:
Never do “real work” in an event handler, or in an timer event.
NETMF runs a lot of these events on a single thread, and as long as a event is executed, no other event that is processed on this one thread will be fired.
And also put a try/catch block in every event handler and thread proc. If a exception is not caught there, the whole program will crash and the board reboots.
I have created a ThreadPool class to simply spawn an async operation without creating new threads all the time.
You can find it on CodeShare.
If no debug session is running (Board starts after power up or reset button) then the ‘Break’ like I meant did never happen to me, so it should accept connections at any time.
Only when debugging with VS I saw this imaginary breakpoints.