diff --git a/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpClient_ForServer.cs b/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpClient_ForServer.cs index 334824a..c3882ca 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpClient_ForServer.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpClient_ForServer.cs @@ -33,6 +33,8 @@ namespace PepperDash.Core public event EventHandler TextReceived; + public event EventHandler AutoReconnectTriggered; + /// /// Event for Receiving text. Once subscribed to this event the receive callback will start a thread that dequeues the messages and invokes the event on a new thread. /// It is not recommended to use both the TextReceived event and the TextReceivedQueueInvoke event. @@ -559,6 +561,8 @@ namespace PepperDash.Core RetryTimer.Stop(); RetryTimer = null; } + if(AutoReconnectTriggered != null) + AutoReconnectTriggered(this, new EventArgs()); RetryTimer = new CTimer(o => Connect(), rndTime); } } diff --git a/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpServer.cs b/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpServer.cs index 3f21ac3..ea9c606 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpServer.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpServer.cs @@ -416,7 +416,7 @@ namespace PepperDash.Core } else { - KillServer(); + //KillServer(); Remove this to be able to reactivate listener if it stops itself due to max clients without disconnecting connected clients. SecureServer.PortNumber = Port; } ServerStopped = false; @@ -703,7 +703,10 @@ namespace PepperDash.Core { Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Error in Socket Status Change Callback. Error: {0}", ex); } - onConnectionChange(clientIndex, server.GetServerSocketStatusForSpecificClient(clientIndex)); + //Use a thread for this event so that the server state updates to listening while this event is processed. Listening must be added to the server state + //after every client connection so that the server can check and see if it is at max clients. Due to this the event fires and server listening enum bit flag + //is not set. Putting in a thread allows the state to update before this event processes so that the subscribers to this event get accurate isListening in the event. + CrestronInvoke.BeginInvoke(o => onConnectionChange(clientIndex, server.GetServerSocketStatusForSpecificClient(clientIndex)), null); } #endregion