I have a web server running on an Netduino plus using the HttpListener listening for client requests and responding with a simple html. I am investigating a problem at a project installation, where the web server stops responding after few days of working (client requests are not so often, once in a day or even longer). I tried to reproduce the problem but did not succeed. However, during testing I noticed that one way to make the web server non-responsive is to send a burst of requests - i did this by keeping F5 key pressed in the internet explorer (continously refereshes). After this, the web server stops responding. First, the code (simplified):
internal static void RunServer() { HttpListener listener = new HttpListener("http", -1); listener.Start(); while (true) { try { Debug.Print("Listening.."); HttpListenerContext context = null; context = listener.GetContext(); Debug.Print("Received request from " + context.Request.UserHostAddress.ToString()); context.Response.ContentType = "text/html"; string html = "<html><p>Hello World " + DateTime.Now.ToString() + "</p></html>"; System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); byte[] messageBody = encoding.GetBytes(html); context.Response.OutputStream.Write(messageBody, 0, messageBody.Length); if (context.Response != null) context.Response.Close(); } catch (Exception e) { Debug.Print("Exception occured! " + e.Message); PowerState.RebootDevice(true, 1000); } } }Next, the version information:
.NetMF v4.1.2821.0
NetduinoPlus, Build Date:Mar 26 2011 02:15:31
ARM Compiler version 400902
TinyCLR (Build 4.1.2821.0)
Finally, the exception (as seen on MF Deploy console)
Listening..
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (5) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::accept [IP: 0000] ####
#### System.Net.Sockets.Socket::Accept [IP: 001c] ####
#### System.Net.HttpListener::AcceptThreadFunc [IP: 0020] ####
#### SocketException ErrorCode = 10056
Received request from 4.0.0.0
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (4) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::send [IP: 0000] ####
#### System.Net.Sockets.Socket::Send [IP: 0018] ####
#### System.Net.Sockets.NetworkStream::Write [IP: 0051] ####
#### System.Net.OutputNetworkStreamWrapper::Write [IP: 0017] ####
#### System.Net.HttpListenerResponse::SendHeaders [IP: 0021] ####
#### System.Net.OutputNetworkStreamWrapper::Write [IP: 000d] ####
#### NetduinoTest.WebServer::RunServer [IP: 0074] ####
#### SocketException ErrorCode = 10056
Exception occured! Exception was thrown: System.Net.Sockets.SocketException
Any pointers on this would be really helpful to me! Thank you!
Ganesh