mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-11 18:54:43 +00:00
Fixed undesirable auto-reconnect behavior when manually disconnecting
This commit is contained in:
@@ -147,7 +147,7 @@ namespace PepperDash.Core
|
||||
IsConnected = true;
|
||||
Debug.Console(1, this, "Connected");
|
||||
TheStream = Client.CreateShellStream("PDTShell", 100, 80, 100, 200, 65534);
|
||||
TheStream.DataReceived += Stream_DataReceived;
|
||||
TheStream.DataReceived += Stream_DataReceived;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -162,14 +162,18 @@ namespace PepperDash.Core
|
||||
Key, Hostname, Port, ie.GetType());
|
||||
else if (ie is SshAuthenticationException)
|
||||
{
|
||||
msg = string.Format("'{0}' Authentication failure for username '{1}', ({2})",
|
||||
msg = string.Format("'{0}' Authentication failure for username '{1}', ({2})",
|
||||
Username, Key, ie.GetType());
|
||||
Debug.Console(0, this, "Authentication failure for username '{0}', ({1})",
|
||||
Debug.Console(0, this, "Authentication failure for username '{0}', ({1})",
|
||||
Username, ie.GetType());
|
||||
}
|
||||
else
|
||||
Debug.Console(0, this, "Error on connect:\r({0})", e);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Console(0, this, "Unhandled exception on connect:\r({0})", e);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -13,17 +13,64 @@ namespace PepperDash.Core
|
||||
{
|
||||
public class GenericTcpIpClient : Device, IBasicCommunication, IAutoReconnect
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public TCPClient Client { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool IsConnected { get { return Client.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED; } }
|
||||
public string Status { get { return Client.ClientStatus.ToString(); } }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SocketStatus ClientStatus { get { return Client.ClientStatus; } }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string ClientStatusText { get { return Client.ClientStatus.ToString(); } }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public ushort UClientStatus { get { return (ushort)Client.ClientStatus; } }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string ConnectionFailure { get { return Client.ClientStatus.ToString(); } }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool AutoReconnect { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int AutoReconnectIntervalMs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Set only when the disconnect method is called.
|
||||
/// </summary>
|
||||
bool DisconnectCalledByUser;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool Connected
|
||||
{
|
||||
get { return Client.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED; }
|
||||
@@ -52,10 +99,12 @@ namespace PepperDash.Core
|
||||
public void Connect()
|
||||
{
|
||||
Client.ConnectToServerAsync(null);
|
||||
DisconnectCalledByUser = false;
|
||||
}
|
||||
|
||||
public void Disconnnect()
|
||||
{
|
||||
DisconnectCalledByUser = true;
|
||||
Client.DisconnectFromServer();
|
||||
}
|
||||
|
||||
@@ -126,12 +175,11 @@ namespace PepperDash.Core
|
||||
|
||||
void Client_SocketStatusChange(TCPClient client, SocketStatus clientSocketStatus)
|
||||
{
|
||||
if (client.ClientStatus != SocketStatus.SOCKET_STATUS_CONNECTED &&
|
||||
client.ClientStatus != SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY)
|
||||
|
||||
Debug.Console(2, this, "Socket status change {0} ({1})", clientSocketStatus, UClientStatus);
|
||||
if (client.ClientStatus != SocketStatus.SOCKET_STATUS_CONNECTED && !DisconnectCalledByUser)
|
||||
WaitAndTryReconnect();
|
||||
|
||||
|
||||
Debug.Console(2, this, "Socket status change {0}", clientSocketStatus);
|
||||
switch (clientSocketStatus)
|
||||
{
|
||||
case SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY:
|
||||
@@ -140,6 +188,7 @@ namespace PepperDash.Core
|
||||
break;
|
||||
case SocketStatus.SOCKET_STATUS_CONNECTED:
|
||||
Client.ReceiveDataAsync(Receive);
|
||||
DisconnectCalledByUser = false;
|
||||
break;
|
||||
case SocketStatus.SOCKET_STATUS_CONNECT_FAILED:
|
||||
break;
|
||||
|
||||
18
Pepperdash Core/Pepperdash Core/Network/DiscoveryThings.cs
Normal file
18
Pepperdash Core/Pepperdash Core/Network/DiscoveryThings.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Core
|
||||
{
|
||||
|
||||
public static class NetworkComm
|
||||
{
|
||||
|
||||
static NetworkComm()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -72,6 +72,7 @@
|
||||
<Compile Include="Device.cs" />
|
||||
<Compile Include="EthernetHelper.cs" />
|
||||
<Compile Include="Comm\GenericTcpIpClient.cs" />
|
||||
<Compile Include="Network\DiscoveryThings.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<None Include="Properties\ControlSystem.cfg" />
|
||||
</ItemGroup>
|
||||
@@ -84,7 +85,7 @@
|
||||
<Programmer />
|
||||
<ArchiveFilename>C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.clz</ArchiveFilename>
|
||||
<MinFirmwareVersion>1.007.0017</MinFirmwareVersion>
|
||||
<CompiledOn>9/2/2016 4:24:23 PM</CompiledOn>
|
||||
<CompiledOn>9/12/2016 2:06:04 PM</CompiledOn>
|
||||
<AdditionalInfo />
|
||||
<EmbedSourceArchive>False</EmbedSourceArchive>
|
||||
<CopyTo />
|
||||
|
||||
Binary file not shown.
@@ -10,7 +10,7 @@
|
||||
<ArchiveName />
|
||||
</RequiredInfo>
|
||||
<OptionalInfo>
|
||||
<CompiledOn>9/2/2016 4:24:23 PM</CompiledOn>
|
||||
<CompilerRev>1.0.0.27730</CompilerRev>
|
||||
<CompiledOn>9/12/2016 2:06:04 PM</CompiledOn>
|
||||
<CompilerRev>1.0.0.23581</CompilerRev>
|
||||
</OptionalInfo>
|
||||
</ProgramInfo>
|
||||
@@ -1,4 +1,4 @@
|
||||
MainAssembly=PepperDash_Core.dll:91ae222c64760e498b41b5b05b1e591d
|
||||
MainAssembly=PepperDash_Core.dll:841414db99de3a39f802c9ba80e23ad1
|
||||
MainAssemblyMinFirmwareVersion=1.007.0017
|
||||
ü
|
||||
DependencySource=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user