Ssh Connect() now spins up new clients. Seems to be helping deal with connection failures

This commit is contained in:
Heath Volmer
2016-12-06 16:02:49 -07:00
parent d7613d2f52
commit 15cd23a857
7 changed files with 32 additions and 31 deletions

View File

@@ -126,10 +126,10 @@ namespace PepperDash.Core
CTimer ReconnectTimer;
string PreviousHostname;
int PreviousPort;
string PreviousUsername;
string PreviousPassword;
//string PreviousHostname;
//int PreviousPort;
//string PreviousUsername;
//string PreviousPassword;
/// <summary>
/// Typical constructor.
@@ -213,37 +213,37 @@ namespace PepperDash.Core
PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(Username, Password);
// Make a new client if we need it or things have changed
if (Client == null || PropertiesHaveChanged())
{
//if (Client == null || PropertiesHaveChanged())
//{
if (Client != null)
{
Debug.Console(2, this, "Cleaning up disconnected client");
Client.ErrorOccurred -= Client_ErrorOccurred;
if (TheStream != null)
{
TheStream.DataReceived -= Stream_DataReceived;
TheStream.ErrorOccurred -= TheStream_ErrorOccurred;
}
TheStream = null;
KillStream();
//if (TheStream != null)
//{
// TheStream.DataReceived -= Stream_DataReceived;
// TheStream.ErrorOccurred -= TheStream_ErrorOccurred;
//}
//TheStream = null;
}
Debug.Console(2, this, "Creating new SshClient");
ConnectionInfo connectionInfo = new ConnectionInfo(Hostname, Port, Username, pauth, kauth);
Client = new SshClient(connectionInfo);
Client.ErrorOccurred += Client_ErrorOccurred;
}
PreviousHostname = Hostname;
PreviousPassword = Password;
PreviousPort = Port;
PreviousUsername = Username;
//}
//PreviousHostname = Hostname;
//PreviousPassword = Password;
//PreviousPort = Port;
//PreviousUsername = Username;
//You can do it!
ClientStatus = SocketStatus.SOCKET_STATUS_WAITING;
try
{
Client.Connect();
#warning We are getting past here with a false IsConnected when it appears to be connected
// Have to assume client is connected cause Client.IsConnected is busted in some cases
// All other conditions *should* error out...
@@ -256,10 +256,10 @@ namespace PepperDash.Core
TheStream.ErrorOccurred += TheStream_ErrorOccurred;
Debug.Console(1, this, "Connected");
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECTED;
PreviousHostname = Hostname;
PreviousPassword = Password;
PreviousPort = Port;
PreviousUsername = Username;
//PreviousHostname = Hostname;
//PreviousPassword = Password;
//PreviousPort = Port;
//PreviousUsername = Username;
//}
return; // Success will not pass here
}
@@ -305,6 +305,7 @@ namespace PepperDash.Core
}
KillStream();
Client.Disconnect();
Client = null;
ClientStatus = SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY;
Debug.Console(1, this, "Disconnected");
}
@@ -352,11 +353,11 @@ namespace PepperDash.Core
}
}
bool PropertiesHaveChanged()
{
return Hostname != PreviousHostname || Port != PreviousPort
|| Username != PreviousUsername || Password != PreviousPassword;
}
//bool PropertiesHaveChanged()
//{
// return Hostname != PreviousHostname || Port != PreviousPort
// || Username != PreviousUsername || Password != PreviousPassword;
//}
/// <summary>
/// Handles the keyboard interactive authentication, should it be required.

View File

@@ -10,8 +10,8 @@
<ArchiveName />
</RequiredInfo>
<OptionalInfo>
<CompiledOn>12/6/2016 2:53:00 PM</CompiledOn>
<CompilerRev>1.0.0.26789</CompilerRev>
<CompiledOn>12/6/2016 3:50:54 PM</CompiledOn>
<CompilerRev>1.0.0.28526</CompilerRev>
</OptionalInfo>
<Plugin>
<Version>Crestron.SIMPLSharp, Version=2.0.48.0, Culture=neutral, PublicKeyToken=812d080f93e2de10</Version>

View File

@@ -1,4 +1,4 @@
MainAssembly=PepperDash_Core.dll:3a5fe881bafa819e1046cf092f48b180
MainAssembly=PepperDash_Core.dll:2fe05eb2518594f4d27bd9ae43dc7a02
MainAssemblyMinFirmwareVersion=1.007.0017
MainAssemblyResource=SimplSharpData.dat:315526abf906cded47fb0c7510266a7e
ü