Skip to content

Commit

Permalink
Fixed issue mtconnect#6
Browse files Browse the repository at this point in the history
The mListenThread.AcceptTcpClient call is executed only if the mListenThread.Pending returns true in order to prevent the blocking call

Closes mtconnect#6
  • Loading branch information
Lorenzo Cicala committed Mar 9, 2020
1 parent 85700ab commit 30a96d6
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/MTCAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 30a96d6

Please sign in to comment.