Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Comm/GenericTcpIpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public GenericTcpIpClient(string key, string address, int port, int bufferSize)
{
StreamDebugging = new CommunicationStreamDebugging(key);
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
AutoReconnectIntervalMs = 5000;
Hostname = address;
Port = port;
Expand All @@ -206,6 +207,7 @@ public GenericTcpIpClient(string key)
{
StreamDebugging = new CommunicationStreamDebugging(key);
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
AutoReconnectIntervalMs = 5000;
BufferSize = 2000;

Expand All @@ -223,6 +225,7 @@ public GenericTcpIpClient()
{
StreamDebugging = new CommunicationStreamDebugging(SplusKey);
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
AutoReconnectIntervalMs = 5000;
BufferSize = 2000;

Expand Down Expand Up @@ -252,6 +255,19 @@ void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType progr
}
}

/// <summary>
/// Handles reconnecting when
/// </summary>
void CrestronEnvironment_EthernetEventHandler(EthernetEventArgs ethernetEventArgs)
{
if (ethernetEventArgs.EthernetEventType == eEthernetEventType.LinkUp)
{
if(_client != null)
Connect();
}

}

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -295,12 +311,14 @@ public void Connect()
}
else
{
Debug.Console(1, this, "Creating new TCPClient");
//Stop retry timer if running
RetryTimer.Stop();
_client = new TCPClient(Hostname, Port, BufferSize);
_client.SocketStatusChange -= Client_SocketStatusChange;
_client.SocketStatusChange += Client_SocketStatusChange;
DisconnectCalledByUser = false;
RetryTimer.Reset();
_client.ConnectToServerAsync(ConnectToServerCallback);
}
}
Expand Down Expand Up @@ -500,6 +518,7 @@ void Client_SocketStatusChange(TCPClient client, SocketStatus clientSocketStatus
else
{
Debug.Console(1, this, "Socket status change {0} ({1})", clientSocketStatus, ClientStatusText);
RetryTimer.Stop();
_client.ReceiveDataAsync(Receive);
}

Expand Down