I worked on some connection between a PC and raspberry PI 2 with Windows 10 IoT (build 10586 TH2) using the "StreamSocketListener". This seems to work fine in debug mode, but when testing the code in the "StreamSocketListener" release mode, it seems to accidentally stop responding.
In debug mode in RPI2, I had sessions with 100k requests without any one problem, but when I press release build, it stops, accidentally, pretty quickly (usually after several hundred requests). The request has a static type, so the input is the same every time.
Has anyone experienced the same problem, and is there a solution to this problem?
The code is based on this blog post:
Simple HTTP server in progress for Windows 8 Metro applications
private void Listen()
{
_listener = new StreamSocketListener();
_listener.ConnectionReceived += (s, e) => ProcessRequestAsync(e.Socket);
_listener.BindServiceNameAsync(requestPort.ToString());
}
private async void ProcessRequestAsync(StreamSocket socket)
{
try
{
StringBuilder request = new StringBuilder();
using (IInputStream input = socket.InputStream)
{
byte[] data = new byte[BufferSize];
IBuffer buffer = data.AsBuffer();
uint dataRead = BufferSize;
while (dataRead == BufferSize)
{
await input.ReadAsync(buffer, BufferSize, InputStreamOptions.Partial);
request.Append(Encoding.UTF8.GetString(data, 0, data.Length));
dataRead = buffer.Length;
}
}
using (IOutputStream output = socket.OutputStream)
{
string requestMethod = request.ToString().Split('\n')[0];
string[] requestParts = requestMethod.Split(' ');
if (requestParts[0] == "GET")
await WriteResponseAsync(requestParts[1], output);
else
throw new InvalidDataException("HTTP method not supported: "
+ requestParts[0]);
}
}
catch (Exception e)
{
Debug.WriteLine("Main ex: " + e);
}
RequestCount++;
}
source
share