mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-04-12 03:57:08 +00:00
fix: adds ethernet event handler to GenericTcpClient to connect on link up status
This commit is contained in:
parent
51c262fce2
commit
59c1212dd3
1 changed files with 20 additions and 0 deletions
|
|
@ -186,6 +186,7 @@ namespace PepperDash.Core
|
||||||
{
|
{
|
||||||
StreamDebugging = new CommunicationStreamDebugging(key);
|
StreamDebugging = new CommunicationStreamDebugging(key);
|
||||||
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
||||||
|
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
|
||||||
AutoReconnectIntervalMs = 5000;
|
AutoReconnectIntervalMs = 5000;
|
||||||
Hostname = address;
|
Hostname = address;
|
||||||
Port = port;
|
Port = port;
|
||||||
|
|
@ -206,6 +207,7 @@ namespace PepperDash.Core
|
||||||
{
|
{
|
||||||
StreamDebugging = new CommunicationStreamDebugging(key);
|
StreamDebugging = new CommunicationStreamDebugging(key);
|
||||||
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
||||||
|
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
|
||||||
AutoReconnectIntervalMs = 5000;
|
AutoReconnectIntervalMs = 5000;
|
||||||
BufferSize = 2000;
|
BufferSize = 2000;
|
||||||
|
|
||||||
|
|
@ -223,6 +225,7 @@ namespace PepperDash.Core
|
||||||
{
|
{
|
||||||
StreamDebugging = new CommunicationStreamDebugging(SplusKey);
|
StreamDebugging = new CommunicationStreamDebugging(SplusKey);
|
||||||
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
||||||
|
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
|
||||||
AutoReconnectIntervalMs = 5000;
|
AutoReconnectIntervalMs = 5000;
|
||||||
BufferSize = 2000;
|
BufferSize = 2000;
|
||||||
|
|
||||||
|
|
@ -252,6 +255,19 @@ namespace PepperDash.Core
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles reconnecting when
|
||||||
|
/// </summary>
|
||||||
|
void CrestronEnvironment_EthernetEventHandler(EthernetEventArgs ethernetEventArgs)
|
||||||
|
{
|
||||||
|
if (ethernetEventArgs.EthernetEventType == eEthernetEventType.LinkUp)
|
||||||
|
{
|
||||||
|
if(_client != null)
|
||||||
|
Connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -295,12 +311,14 @@ namespace PepperDash.Core
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Debug.Console(1, this, "Creating new TCPClient");
|
||||||
//Stop retry timer if running
|
//Stop retry timer if running
|
||||||
RetryTimer.Stop();
|
RetryTimer.Stop();
|
||||||
_client = new TCPClient(Hostname, Port, BufferSize);
|
_client = new TCPClient(Hostname, Port, BufferSize);
|
||||||
_client.SocketStatusChange -= Client_SocketStatusChange;
|
_client.SocketStatusChange -= Client_SocketStatusChange;
|
||||||
_client.SocketStatusChange += Client_SocketStatusChange;
|
_client.SocketStatusChange += Client_SocketStatusChange;
|
||||||
DisconnectCalledByUser = false;
|
DisconnectCalledByUser = false;
|
||||||
|
RetryTimer.Reset();
|
||||||
_client.ConnectToServerAsync(ConnectToServerCallback);
|
_client.ConnectToServerAsync(ConnectToServerCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -376,6 +394,7 @@ namespace PepperDash.Core
|
||||||
{
|
{
|
||||||
if (c.ClientStatus != SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (c.ClientStatus != SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
{
|
{
|
||||||
|
Debug.LogError(Debug.ErrorLogLevel.Error, string.Format("{0}: Server connection result: {1}", Key, c.ClientStatus));
|
||||||
Debug.Console(0, this, "Server connection result: {0}", c.ClientStatus);
|
Debug.Console(0, this, "Server connection result: {0}", c.ClientStatus);
|
||||||
WaitAndTryReconnect();
|
WaitAndTryReconnect();
|
||||||
}
|
}
|
||||||
|
|
@ -500,6 +519,7 @@ namespace PepperDash.Core
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Socket status change {0} ({1})", clientSocketStatus, ClientStatusText);
|
Debug.Console(1, this, "Socket status change {0} ({1})", clientSocketStatus, ClientStatusText);
|
||||||
|
RetryTimer.Stop();
|
||||||
_client.ReceiveDataAsync(Receive);
|
_client.ReceiveDataAsync(Receive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue