C # Windows 10 IoT StreamSocketListener randomly stops listening in release mode

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
        {
            // this works for text only
            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++;
    }
+4
source share
3 answers

After a long long-term test with the "Compiling with .NET Native tool chain" setting enabled for my UWP project, this problem seems to be fixed. When you disable this feature, the problem occurs after a couple of minutes.

Since I cannot accept the comment as an answer, I will simply answer my question and agree with it. But all thanks to Matt for pointing me in the right direction.

Interesting ... does this still play if you disable the .NET Native compilation? (Project Properties> BUILD> "Enable .NET Native toolchain") - Matt Whilden

+3
source

, : RPi3, Win-IoT 10.0.14393.693, # Gnm : StreamSocketListener , / HTTP- POST, ( -) .

: ) , , . ) " .NET Native Tool chain", "ON"!

Gnm, OFF, : , , . , . , , Gnm...

0

FYI I had the same issue for Windows 10 Iot C #. The mine was fixed by the option “Compile using the .NET Native Tool network”, switched to “ON”, then the option “Compile using the .NET Native Tool network” switched to “OFF”!

0
source

Source: https://habr.com/ru/post/1625202/


All Articles