locked
StreamSocketListener stops responding in deployment but works in debug RRS feed

  • Question

  • I am having a issue with the  StreamSocketListener. It works for about 5 mins when I deploy to a Raspberry Pi but in debug mode it works with no issues.

    My code looks like this:

     private async void DataListener_OpenListenPorts()
            {
                StreamSocketListener listener = new StreamSocketListener();
                listener.ConnectionReceived += SocketListener_ConnectionReceived;
                listener.Control.KeepAlive = true;
                localHost = DeviceInfo.GetCurrentIpv4Address();
                hostName = new HostName(localHost);
                try
                {              
                    string ServerName = RX_Connection_Port.Text.ToString();
                    await listener.BindEndpointAsync(hostName, ServerName);
                    // await listener.BindServiceNameAsync(ServerName);
                }
                catch (Exception exception)
                {
                    if (Windows.Networking.Sockets.SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown)
                    {
                        throw;
                    }
                  //  Debug.WriteLine("Start listening failed with error: " + exception.Message);
                }
            }
         
            private async void SocketListener_ConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
            {
              
                    Stream inStream = args.Socket.InputStream.AsStreamForRead();
                    StreamReader reader = new StreamReader(inStream);
                    string request = await reader.ReadLineAsync();
                    if (request != null)
                    {
                        incoming = request;
                        await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            SynthPlayback(incoming);
                        });
                    inStream.Flush();
                    inStream.Dispose();
                    }
               
            }

    As I mentioned it runs perfect in debug but stops in deploy mode.

    I have tried to turn on and off Compile in .Net native tool chain(mentioned in other posts) but that did not make a difference.

    Any idea why it would just stop working only after deploying?

    Thursday, November 9, 2017 1:06 AM

Answers

  • Hi, CMCTS

       I have tested the code on v.10.0.16299.19, can not reproduce this issue. I have found the same topic in StackOverflow. I uploaded my project on GitHub, please download it and test again. If the error still exist, please feel free let me know.

    Best Regards,

    Michael


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Andre MarschalekMVP Friday, November 17, 2017 12:27 PM
    • Marked as answer by CMCTS Sunday, November 19, 2017 2:59 PM
    Monday, November 13, 2017 6:01 AM

All replies

  • Hi, CMCTS

            I have tested your code with running about half an hour, it runs perfect, I can see the received message by using Windows IoT Remote Client tool to connect Raspberry. Could you let know which version your windows iot core is, and the details about how you tested.

            By the way, .Net Native Tool Chain is a precompilation technology, you can see Compiling Apps with .NET Native.

    Best Regards,

    Michael


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 10, 2017 6:44 AM
  • Thank you for your feedback and taking the time to test my code.

    I will check the version when i get back to the office.

    Basically i have the PI sitting on the network always listening for data to come in from another client.The other client connects,sends the string, then disconnects. Sometimes even before i have had a change to have the client send data the listener just stops. I have confirmed in netstat that it does start but stops randomly. I also have a UI button to restart the listener which it does but again it will just stop on its own. I really need for it just to keep listening on that port for data even if nothing comes in for a while.  In debug mode it does not seem to stop at all even after no activity.

    I will check the version tonight. Which version were you testing on?

    Friday, November 10, 2017 9:01 PM
  • The running version of Windows is 

    v.10.0.16299.19

    When the application is first launched it will start to listen(netstat -a) shows Listening.

    After a undetermined time of no activity netstat -a shows the socket is no longer open and listening.

    Tried formatting and reinstalling the OS but same result.

    • Edited by CMCTS Saturday, November 11, 2017 8:24 PM
    Saturday, November 11, 2017 1:20 PM
  • Hi, CMCTS

       I have tested the code on v.10.0.16299.19, can not reproduce this issue. I have found the same topic in StackOverflow. I uploaded my project on GitHub, please download it and test again. If the error still exist, please feel free let me know.

    Best Regards,

    Michael


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Andre MarschalekMVP Friday, November 17, 2017 12:27 PM
    • Marked as answer by CMCTS Sunday, November 19, 2017 2:59 PM
    Monday, November 13, 2017 6:01 AM
  • If you are using inside a BackgroundTask project, make sure you are obtaining the deferral in the first place.

    https://docs.microsoft.com/en-us/windows/iot-core/develop-your-app/backgroundapplications

    Beeing that said, from this point of view, the behaviour should be the same in Debug also.


    Monday, November 13, 2017 6:53 AM
  • I have loaded that code. This is just one class from the over all program, but if it stays stable and keeps running then I have to wonder what in my code would cause the socket to close.

    I will post my findings as testing progresses. I plan on just letting this run for a few days and see if it stays running.

    Thank you for your efforts to test this. 

    Tuesday, November 14, 2017 11:47 AM
  • Hi, CMCTS

        Please feel free to let me know if the issue still exists.

    Best Regards,

    Michael


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by CMCTS Sunday, November 19, 2017 2:58 PM
    • Unmarked as answer by CMCTS Sunday, November 19, 2017 2:59 PM
    Wednesday, November 15, 2017 1:29 AM
  • Update: So I have stripped out all my code with the exception of the listener. I created a tcpClient deck top application to send data to the listener at different intervals and it stayed working. So I have to assume something else in my code is causing the socket to stop I have started to rebuild the application from the ground up. I am running into other problems but those will be posted in a new thread. I think my problem is poorly set up code and I need to figure out what and how to fix it. Thank you for your testing and assistance. Can you recommend good tutorials and or books that are helpful with UWP? Thank you again and I would say this problem is solved.
    Sunday, November 19, 2017 2:58 PM
  • Hi, CMCTS

        You can refer to the StreamSocket sample in GitHub.Of course, when you create a tcpclient desktop application to send data to the StreamSocketListener in this sample, you need to modify data receiving by DataReader, if not may be cause an exception. You can also refer to this article.

    Best Regards,

    Michael


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 20, 2017 2:56 AM