fix(GenericSshClient): #110 Adds check to ensure TheStream != null and IsConnected in SendText() and SentBytes()

This commit is contained in:
Neil Dorin
2021-07-30 13:49:57 -06:00
parent bace67d3e1
commit 5779842e9a

View File

@@ -435,7 +435,7 @@ namespace PepperDash.Core
{ {
try try
{ {
if (Client != null) if (Client != null && TheStream != null && IsConnected)
{ {
if (StreamDebugging.TxStreamDebuggingIsEnabled) if (StreamDebugging.TxStreamDebuggingIsEnabled)
Debug.Console(0, this, "Sending {0} characters of text: '{1}'", text.Length, ComTextHelper.GetDebugText(text)); Debug.Console(0, this, "Sending {0} characters of text: '{1}'", text.Length, ComTextHelper.GetDebugText(text));
@@ -443,6 +443,10 @@ namespace PepperDash.Core
TheStream.Write(text); TheStream.Write(text);
TheStream.Flush(); TheStream.Flush();
}
else
{
Debug.Console(2, this, "Client is null or disconnected. Cannot Send Text");
} }
} }
catch (Exception ex) catch (Exception ex)
@@ -464,13 +468,17 @@ namespace PepperDash.Core
{ {
try try
{ {
if (Client != null) if (Client != null && TheStream != null && IsConnected)
{ {
if (StreamDebugging.TxStreamDebuggingIsEnabled) if (StreamDebugging.TxStreamDebuggingIsEnabled)
Debug.Console(0, this, "Sending {0} bytes: '{1}'", bytes.Length, ComTextHelper.GetEscapedText(bytes)); Debug.Console(0, this, "Sending {0} bytes: '{1}'", bytes.Length, ComTextHelper.GetEscapedText(bytes));
TheStream.Write(bytes, 0, bytes.Length); TheStream.Write(bytes, 0, bytes.Length);
TheStream.Flush(); TheStream.Flush();
}
else
{
Debug.Console(2, this, "Client is null or disconnected. Cannot Send Bytes");
} }
} }
catch catch