BrandonPotter / SimpleTCP

Straightforward .NET library to handle the repetitive tasks of spinning up and working with TCP sockets (client and server).
Apache License 2.0
368 stars 108 forks source link

missing event/notfication in SimpleTcpClient class for brocken connection #39

Open RedCali opened 6 years ago

RedCali commented 6 years ago

i miss an event / notification in SimpleTcpClient class for broken connection

May the Server or the connection is brocken you do not get a notice for that. So in this case you cant handle it and can't do anything....

Should we add an event for that case? Regards Bastian

RedCali commented 6 years ago

adding the following fixed my issue:

add handler property:

public event EventHandler ConnectionInterrupted;

add the handler:

private void NotifyConnectionInterrupted(TcpClient client, byte[] msg)
{
       ConnectionInterrupted?.Invoke(this, EventArgs.Empty);
}

call handler in "RunLoopStep()":

if (_client.Connected == false)
{
         NotifyConnectionInterrupted(_client, null);
         return;
}