I am having a issue with a socket listener. It will work for a few mins thenjust stops listening. I have tried to enable and disable Compile in .Net option as suggested in other forums with no luck. Any ideas why it would just stop? I need it to be listening at all times for input from another client.
private async void DataListener_OpenListenPorts()
{
StreamSocketListener listener = new StreamSocketListener();
listener.ConnectionReceived += SocketListener_ConnectionReceived;
listener.Control.KeepAlive = true;
try
{
string ServerName = _rxPort.ToString();
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);
});
}
}
In debug mode the socket stays open. This problem only seems to happen in deployment