mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-01-11 19:44:44 +00:00
updated client to add an event for the auto reconnect. Using this event with empty args to catch the client before the next attempt and change the port for a multi server environment. Also updated the server to not kill on a listen so that if the server stops listening due to max clients (does this automatically) it will be able to start listening on when it drops below max clients without disconnecting all connected clients. On server Also udpated the onConnectionChange to fire in its own thread so that the server can update its state and the state will be accurate in the event callbacks. See description in code.
This commit is contained in:
@@ -33,6 +33,8 @@ namespace PepperDash.Core
|
||||
|
||||
public event EventHandler<GenericTcpServerCommMethodReceiveTextArgs> TextReceived;
|
||||
|
||||
public event EventHandler AutoReconnectTriggered;
|
||||
|
||||
/// <summary>
|
||||
/// 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user