mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-17 05:34:48 +00:00
Merge remote-tracking branch 'origin/feature/PDC-9_ReceivedDataAsyncCallbackFixes' into maintenance/PR-1
# Conflicts: # Pepperdash Core/Pepperdash Core/Properties/AssemblyInfo.cs
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -669,6 +669,8 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
if (ClientReadyAfterKeyExchange.Contains(clientIndex))
|
if (ClientReadyAfterKeyExchange.Contains(clientIndex))
|
||||||
ClientReadyAfterKeyExchange.Remove(clientIndex);
|
ClientReadyAfterKeyExchange.Remove(clientIndex);
|
||||||
|
if (WaitingForSharedKey.Contains(clientIndex))
|
||||||
|
WaitingForSharedKey.Remove(clientIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -781,31 +783,33 @@ namespace PepperDash.Core
|
|||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Warning, "Client at index {0} Shared key did not match the server, disconnecting client. Key: {1}", clientIndex, received);
|
Debug.Console(1, this, Debug.ErrorLogLevel.Warning, "Client at index {0} Shared key did not match the server, disconnecting client. Key: {1}", clientIndex, received);
|
||||||
mySecureTCPServer.SendData(clientIndex, b, b.Length);
|
mySecureTCPServer.SendData(clientIndex, b, b.Length);
|
||||||
mySecureTCPServer.Disconnect(clientIndex);
|
mySecureTCPServer.Disconnect(clientIndex);
|
||||||
WaitingForSharedKey.Remove(clientIndex);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mySecureTCPServer.NumberOfClientsConnected > 0)
|
|
||||||
mySecureTCPServer.ReceiveDataAsync(clientIndex, SecureReceivedDataAsyncCallback);
|
|
||||||
WaitingForSharedKey.Remove(clientIndex);
|
WaitingForSharedKey.Remove(clientIndex);
|
||||||
byte[] success = Encoding.GetEncoding(28591).GetBytes("Shared Key Match");
|
byte[] success = Encoding.GetEncoding(28591).GetBytes("Shared Key Match");
|
||||||
mySecureTCPServer.SendDataAsync(clientIndex, success, success.Length, null);
|
mySecureTCPServer.SendDataAsync(clientIndex, success, success.Length, null);
|
||||||
OnServerClientReadyForCommunications(clientIndex);
|
OnServerClientReadyForCommunications(clientIndex);
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Client with index {0} provided the shared key and successfully connected to the server", clientIndex);
|
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Client with index {0} provided the shared key and successfully connected to the server", clientIndex);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
//var address = mySecureTCPServer.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex);
|
else if (!string.IsNullOrEmpty(checkHeartbeat(clientIndex, received)))
|
||||||
//Debug.Console(1, this, "Secure Server Listening on Port: {0}, client IP: {1}, Client Index: {4}, NumberOfBytesReceived: {2}, Received: {3}\r\n",
|
|
||||||
// mySecureTCPServer.PortNumber.ToString(), address , numberOfBytesReceived.ToString(), received, clientIndex.ToString());
|
|
||||||
if (!string.IsNullOrEmpty(checkHeartbeat(clientIndex, received)))
|
|
||||||
onTextReceived(received, clientIndex);
|
onTextReceived(received, clientIndex);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Error Receiving data: {0}. Error: {1}", received, ex);
|
Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Error Receiving data: {0}. Error: {1}", received, ex);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (mySecureTCPServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (mySecureTCPServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
mySecureTCPServer.ReceiveDataAsync(clientIndex, SecureReceivedDataAsyncCallback);
|
mySecureTCPServer.ReceiveDataAsync(clientIndex, SecureReceivedDataAsyncCallback);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If numberOfBytesReceived <= 0
|
||||||
|
mySecureTCPServer.Disconnect(clientIndex);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -174,8 +174,8 @@ namespace PepperDash.Core
|
|||||||
if (Client != null)
|
if (Client != null)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Program stopping. Closing connection");
|
Debug.Console(1, this, "Program stopping. Closing connection");
|
||||||
Client.Disconnect();
|
Disconnect();
|
||||||
Client.Dispose();
|
//Client.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -387,13 +387,16 @@ namespace PepperDash.Core
|
|||||||
myTcpServer.SocketSendOrReceiveTimeOutInMs = (this.HeartbeatRequiredIntervalMs * 5);
|
myTcpServer.SocketSendOrReceiveTimeOutInMs = (this.HeartbeatRequiredIntervalMs * 5);
|
||||||
|
|
||||||
// myTcpServer.HandshakeTimeout = 30;
|
// myTcpServer.HandshakeTimeout = 30;
|
||||||
myTcpServer.SocketStatusChange += new TCPServerSocketStatusChangeEventHandler(TcpServer_SocketStatusChange);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
KillServer();
|
KillServer();
|
||||||
myTcpServer.PortNumber = Port;
|
myTcpServer.PortNumber = Port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
myTcpServer.SocketStatusChange -= TcpServer_SocketStatusChange;
|
||||||
|
myTcpServer.SocketStatusChange += TcpServer_SocketStatusChange;
|
||||||
|
|
||||||
ServerStopped = false;
|
ServerStopped = false;
|
||||||
myTcpServer.WaitForConnectionAsync(IPAddress.Any, TcpConnectCallback);
|
myTcpServer.WaitForConnectionAsync(IPAddress.Any, TcpConnectCallback);
|
||||||
OnServerStateChange(myTcpServer.State);
|
OnServerStateChange(myTcpServer.State);
|
||||||
@@ -670,6 +673,8 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
if (ClientReadyAfterKeyExchange.Contains(clientIndex))
|
if (ClientReadyAfterKeyExchange.Contains(clientIndex))
|
||||||
ClientReadyAfterKeyExchange.Remove(clientIndex);
|
ClientReadyAfterKeyExchange.Remove(clientIndex);
|
||||||
|
if (WaitingForSharedKey.Contains(clientIndex))
|
||||||
|
WaitingForSharedKey.Remove(clientIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -763,14 +768,14 @@ namespace PepperDash.Core
|
|||||||
/// <param name="mySecureTCPServer"></param>
|
/// <param name="mySecureTCPServer"></param>
|
||||||
/// <param name="clientIndex"></param>
|
/// <param name="clientIndex"></param>
|
||||||
/// <param name="numberOfBytesReceived"></param>
|
/// <param name="numberOfBytesReceived"></param>
|
||||||
void TcpServerReceivedDataAsyncCallback(TCPServer mySecureTCPServer, uint clientIndex, int numberOfBytesReceived)
|
void TcpServerReceivedDataAsyncCallback(TCPServer myTCPServer, uint clientIndex, int numberOfBytesReceived)
|
||||||
{
|
{
|
||||||
if (numberOfBytesReceived > 0)
|
if (numberOfBytesReceived > 0)
|
||||||
{
|
{
|
||||||
string received = "Nothing";
|
string received = "Nothing";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
byte[] bytes = mySecureTCPServer.GetIncomingDataBufferForSpecificClient(clientIndex);
|
byte[] bytes = myTCPServer.GetIncomingDataBufferForSpecificClient(clientIndex);
|
||||||
received = System.Text.Encoding.GetEncoding(28591).GetString(bytes, 0, numberOfBytesReceived);
|
received = System.Text.Encoding.GetEncoding(28591).GetString(bytes, 0, numberOfBytesReceived);
|
||||||
if (WaitingForSharedKey.Contains(clientIndex))
|
if (WaitingForSharedKey.Contains(clientIndex))
|
||||||
{
|
{
|
||||||
@@ -780,33 +785,34 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
byte[] b = Encoding.GetEncoding(28591).GetBytes("Shared key did not match server. Disconnecting");
|
byte[] b = Encoding.GetEncoding(28591).GetBytes("Shared key did not match server. Disconnecting");
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Warning, "Client at index {0} Shared key did not match the server, disconnecting client. Key: {1}", clientIndex, received);
|
Debug.Console(1, this, Debug.ErrorLogLevel.Warning, "Client at index {0} Shared key did not match the server, disconnecting client. Key: {1}", clientIndex, received);
|
||||||
mySecureTCPServer.SendData(clientIndex, b, b.Length);
|
myTCPServer.SendData(clientIndex, b, b.Length);
|
||||||
mySecureTCPServer.Disconnect(clientIndex);
|
myTCPServer.Disconnect(clientIndex);
|
||||||
WaitingForSharedKey.Remove(clientIndex);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mySecureTCPServer.NumberOfClientsConnected > 0)
|
|
||||||
mySecureTCPServer.ReceiveDataAsync(clientIndex, TcpServerReceivedDataAsyncCallback);
|
|
||||||
WaitingForSharedKey.Remove(clientIndex);
|
WaitingForSharedKey.Remove(clientIndex);
|
||||||
byte[] success = Encoding.GetEncoding(28591).GetBytes("Shared Key Match");
|
byte[] success = Encoding.GetEncoding(28591).GetBytes("Shared Key Match");
|
||||||
mySecureTCPServer.SendDataAsync(clientIndex, success, success.Length, null);
|
myTCPServer.SendDataAsync(clientIndex, success, success.Length, null);
|
||||||
OnServerClientReadyForCommunications(clientIndex);
|
OnServerClientReadyForCommunications(clientIndex);
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Client with index {0} provided the shared key and successfully connected to the server", clientIndex);
|
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Client with index {0} provided the shared key and successfully connected to the server", clientIndex);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
//var address = mySecureTCPServer.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex);
|
|
||||||
//Debug.Console(1, this, "Secure Server Listening on Port: {0}, client IP: {1}, Client Index: {4}, NumberOfBytesReceived: {2}, Received: {3}\r\n",
|
else if (!string.IsNullOrEmpty(checkHeartbeat(clientIndex, received)))
|
||||||
// mySecureTCPServer.PortNumber.ToString(), address , numberOfBytesReceived.ToString(), received, clientIndex.ToString());
|
|
||||||
if (!string.IsNullOrEmpty(checkHeartbeat(clientIndex, received)))
|
|
||||||
onTextReceived(received, clientIndex);
|
onTextReceived(received, clientIndex);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Error Receiving data: {0}. Error: {1}", received, ex);
|
Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Error Receiving data: {0}. Error: {1}", received, ex);
|
||||||
}
|
}
|
||||||
|
if (myTCPServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
|
myTCPServer.ReceiveDataAsync(clientIndex, TcpServerReceivedDataAsyncCallback);
|
||||||
}
|
}
|
||||||
if (mySecureTCPServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
else
|
||||||
mySecureTCPServer.ReceiveDataAsync(clientIndex, TcpServerReceivedDataAsyncCallback);
|
{
|
||||||
|
// If numberOfBytesReceived <= 0
|
||||||
|
myTCPServer.Disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
static int SaveTimeoutMs = 30000;
|
static int SaveTimeoutMs = 30000;
|
||||||
|
|
||||||
|
public static string PepperDashCoreVersion { get; private set; }
|
||||||
|
|
||||||
static CTimer SaveTimer;
|
static CTimer SaveTimer;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -49,9 +51,9 @@ namespace PepperDash.Core
|
|||||||
// Get the assembly version and print it to console and the log
|
// Get the assembly version and print it to console and the log
|
||||||
var version = Assembly.GetExecutingAssembly().GetName().Version;
|
var version = Assembly.GetExecutingAssembly().GetName().Version;
|
||||||
|
|
||||||
var versionString = string.Format("{0}.{1}.{2}", version.Major, version.Minor, version.Build);
|
PepperDashCoreVersion = string.Format("{0}.{1}.{2}", version.Major, version.Minor, version.Build);
|
||||||
|
|
||||||
var msg = string.Format("[App {0}] Using PepperDash_Core v{1}", InitialParametersClass.ApplicationNumber, versionString);
|
var msg = string.Format("[App {0}] Using PepperDash_Core v{1}", InitialParametersClass.ApplicationNumber, PepperDashCoreVersion);
|
||||||
|
|
||||||
CrestronConsole.PrintLine(msg);
|
CrestronConsole.PrintLine(msg);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user