From 30a96d6cfadc72a03eb73317b4e4dd0894b57df5 Mon Sep 17 00:00:00 2001 From: Lorenzo Cicala Date: Mon, 9 Mar 2020 16:46:53 +0100 Subject: [PATCH] Fixed issue #6 The mListenThread.AcceptTcpClient call is executed only if the mListenThread.Pending returns true in order to prevent the blocking call Closes #6 --- src/MTCAdapter.cs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/MTCAdapter.cs b/src/MTCAdapter.cs index 5ffca151..e125cea4 100644 --- a/src/MTCAdapter.cs +++ b/src/MTCAdapter.cs @@ -519,16 +519,20 @@ private void ListenForClients() { while (mRunning) { - //blocks until a client has connected to the server - TcpClient client = mListener.AcceptTcpClient(); + //loop until there aren't pending clients + if (mListener.Pending()) + { + //get the pending client + TcpClient client = mListener.AcceptTcpClient(); - //create a thread to handle communication - //with connected client - Thread clientThread = new Thread(new ParameterizedThreadStart(HeartbeatClient)); - clientThread.Start(client); + //create a thread to handle communication + //with connected client + Thread clientThread = new Thread(new ParameterizedThreadStart(HeartbeatClient)); + clientThread.Start(client); - SendAllTo(client.GetStream()); - clientThread.Join(); + SendAllTo(client.GetStream()); + clientThread.Join(); + } } } catch (Exception e)