mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-16 13:14:49 +00:00
Completed lib for Dynamic TCP server, need to comment, build SImpl+, and test
This commit is contained in:
Binary file not shown.
@@ -34,12 +34,15 @@ namespace PepperDash_Core
|
|||||||
|
|
||||||
public class DynamicTCPServer : Device
|
public class DynamicTCPServer : Device
|
||||||
{
|
{
|
||||||
|
#region Events
|
||||||
public event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
|
public event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
|
||||||
|
|
||||||
public event EventHandler<DynamicTCPServerSocketStatusChangeEventArgs> ClientConnectionChange;
|
public event EventHandler<DynamicTCPServerSocketStatusChangeEventArgs> ClientConnectionChange;
|
||||||
|
|
||||||
public event EventHandler<DynamicTCPServerStateChangedEventArgs> ServerStateChange;
|
public event EventHandler<DynamicTCPServerStateChangedEventArgs> ServerStateChange;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Properties/Variables
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Secure or unsecure TCP server. Defaults to Unsecure or standard TCP server without SSL
|
/// Secure or unsecure TCP server. Defaults to Unsecure or standard TCP server without SSL
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -64,7 +67,7 @@ namespace PepperDash_Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsConnected
|
public bool IsConnected
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (Secure && SecureServer != null)
|
if (Secure && SecureServer != null)
|
||||||
return SecureServer.State == ServerState.SERVER_CONNECTED;
|
return SecureServer.State == ServerState.SERVER_CONNECTED;
|
||||||
@@ -112,7 +115,18 @@ namespace PepperDash_Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of clients currently connected.
|
/// Number of clients currently connected.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort NumberOfClientsConnected { get; set; }
|
public ushort NumberOfClientsConnected
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Secure && SecureServer != null)
|
||||||
|
return (ushort)SecureServer.NumberOfClientsConnected;
|
||||||
|
else if (!Secure && UnsecureServer != null)
|
||||||
|
return (ushort)UnsecureServer.NumberOfClientsConnected;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Port on server
|
/// Port on server
|
||||||
@@ -132,7 +146,7 @@ namespace PepperDash_Core
|
|||||||
/// Bool to show whether the server requires a preshared key. Must be set the same in the client, and if true shared keys must be identical on server/client
|
/// Bool to show whether the server requires a preshared key. Must be set the same in the client, and if true shared keys must be identical on server/client
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool RequiresPresharedKey { get; set; }
|
public bool RequiresPresharedKey { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// S+ helper for requires shared key bool
|
/// S+ helper for requires shared key bool
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -151,7 +165,7 @@ namespace PepperDash_Core
|
|||||||
/// SharedKey is sent for varification to the server. Shared key can be any text (255 char limit in SIMPL+ Module), but must match the Shared Key on the Server module.
|
/// SharedKey is sent for varification to the server. Shared key can be any text (255 char limit in SIMPL+ Module), but must match the Shared Key on the Server module.
|
||||||
/// If SharedKey changes while server is listening or clients are connected, disconnect and stop listening will be called
|
/// If SharedKey changes while server is listening or clients are connected, disconnect and stop listening will be called
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string SharedKey
|
public string SharedKey
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -159,37 +173,62 @@ namespace PepperDash_Core
|
|||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
if (Secure && SecureServer != null && SecureServer.State == ServerState.SERVER_CONNECTED)
|
||||||
|
DisconnectAllClients();
|
||||||
|
if (!Secure && UnsecureServer != null && UnsecureServer.State == ServerState.SERVER_CONNECTED)
|
||||||
|
DisconnectAllClients();
|
||||||
_SharedKey = value;
|
_SharedKey = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private string _SharedKey;
|
private string _SharedKey;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// flags to show the server is waiting for client at index to send the shared key
|
/// flags to show the secure server is waiting for client at index to send the shared key
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<uint> WaitingForSharedKey = new List<uint>();
|
public List<uint> WaitingForSharedKey = new List<uint>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Store the connected client indexes
|
||||||
|
/// </summary>
|
||||||
|
public List<uint> ConnectedClientsIndexes = new List<uint>();
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defaults to 2000
|
/// Defaults to 2000
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int BufferSize { get; set; }
|
public int BufferSize { get; set; }
|
||||||
|
|
||||||
public string OnlyAcceptConnectionFromAddress { get; set; }
|
public string OnlyAcceptConnectionFromAddress
|
||||||
|
{
|
||||||
|
get { return _OnlyAcceptConnectionFromAddress; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (Secure && SecureServer != null && SecureServer.State == ServerState.SERVER_CONNECTED)
|
||||||
|
DisconnectAllClients();
|
||||||
|
if (!Secure && UnsecureServer != null && UnsecureServer.State == ServerState.SERVER_CONNECTED)
|
||||||
|
DisconnectAllClients();
|
||||||
|
MaxConnections = 1;
|
||||||
|
_OnlyAcceptConnectionFromAddress = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private string _OnlyAcceptConnectionFromAddress;
|
||||||
|
|
||||||
|
private bool ServerStopped { get; set; }
|
||||||
|
|
||||||
public SecureTCPServer SecureServer;
|
public SecureTCPServer SecureServer;
|
||||||
public TCPServer UnsecureServer;
|
public TCPServer UnsecureServer;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
//base class constructor
|
//base class constructor
|
||||||
public DynamicTCPServer()
|
public DynamicTCPServer()
|
||||||
: base("Uninitialized Dynamic TCP Server")
|
: base("Uninitialized Dynamic TCP Server")
|
||||||
{
|
{
|
||||||
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
||||||
BufferSize = 2000;
|
BufferSize = 2000;
|
||||||
Secure = false;
|
Secure = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
|
void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
|
||||||
@@ -201,7 +240,9 @@ namespace PepperDash_Core
|
|||||||
StopListening();
|
StopListening();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods - Server Actions
|
||||||
public void Listen()
|
public void Listen()
|
||||||
{
|
{
|
||||||
if (Port < 1 || Port > 65535)
|
if (Port < 1 || Port > 65535)
|
||||||
@@ -219,10 +260,14 @@ namespace PepperDash_Core
|
|||||||
if (Secure)
|
if (Secure)
|
||||||
{
|
{
|
||||||
if (SecureServer.State == ServerState.SERVER_LISTENING)
|
if (SecureServer.State == ServerState.SERVER_LISTENING)
|
||||||
return;
|
return;
|
||||||
SecureServer = new SecureTCPServer(Port, MaxConnections);
|
SecureServer = new SecureTCPServer(Port, MaxConnections);
|
||||||
SecureServer.SocketStatusChange += new SecureTCPServerSocketStatusChangeEventHandler(SecureServer_SocketStatusChange);
|
SecureServer.SocketStatusChange += new SecureTCPServerSocketStatusChangeEventHandler(SecureServer_SocketStatusChange);
|
||||||
SecureServer.WaitForConnectionAsync(IPAddress.Any, SecureConnectCallback);
|
ServerStopped = false;
|
||||||
|
if (!string.IsNullOrEmpty(OnlyAcceptConnectionFromAddress))
|
||||||
|
SecureServer.WaitForConnectionAsync(OnlyAcceptConnectionFromAddress, SecureConnectCallback);
|
||||||
|
else
|
||||||
|
SecureServer.WaitForConnectionAsync(IPAddress.Any, SecureConnectCallback);
|
||||||
Debug.Console(0, "Secure Server Status: {0}, Socket Status: {1}\r\n", SecureServer.State.ToString(), SecureServer.ServerSocketStatus);
|
Debug.Console(0, "Secure Server Status: {0}, Socket Status: {1}\r\n", SecureServer.State.ToString(), SecureServer.ServerSocketStatus);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -231,13 +276,18 @@ namespace PepperDash_Core
|
|||||||
return;
|
return;
|
||||||
UnsecureServer = new TCPServer(Port, MaxConnections);
|
UnsecureServer = new TCPServer(Port, MaxConnections);
|
||||||
UnsecureServer.SocketStatusChange += new TCPServerSocketStatusChangeEventHandler(UnsecureServer_SocketStatusChange);
|
UnsecureServer.SocketStatusChange += new TCPServerSocketStatusChangeEventHandler(UnsecureServer_SocketStatusChange);
|
||||||
UnsecureServer.WaitForConnectionAsync(IPAddress.Any, UnsecureConnectCallback);
|
ServerStopped = false;
|
||||||
|
if (!string.IsNullOrEmpty(OnlyAcceptConnectionFromAddress))
|
||||||
|
UnsecureServer.WaitForConnectionAsync(OnlyAcceptConnectionFromAddress, UnsecureConnectCallback);
|
||||||
|
else
|
||||||
|
UnsecureServer.WaitForConnectionAsync(IPAddress.Any, UnsecureConnectCallback);
|
||||||
Debug.Console(0, "Unsecure Server Status: {0}, Socket Status: {1}\r\n", UnsecureServer.State.ToString(), UnsecureServer.ServerSocketStatus);
|
Debug.Console(0, "Unsecure Server Status: {0}, Socket Status: {1}\r\n", UnsecureServer.State.ToString(), UnsecureServer.ServerSocketStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StopListening()
|
public void StopListening()
|
||||||
{
|
{
|
||||||
|
Debug.Console(0, "Stopping Listener");
|
||||||
if (SecureServer != null && SecureServer.State == ServerState.SERVER_LISTENING)
|
if (SecureServer != null && SecureServer.State == ServerState.SERVER_LISTENING)
|
||||||
SecureServer.Stop();
|
SecureServer.Stop();
|
||||||
if (UnsecureServer != null && UnsecureServer.State == ServerState.SERVER_LISTENING)
|
if (UnsecureServer != null && UnsecureServer.State == ServerState.SERVER_LISTENING)
|
||||||
@@ -245,16 +295,195 @@ namespace PepperDash_Core
|
|||||||
var handler = ServerStateChange;
|
var handler = ServerStateChange;
|
||||||
if (ServerStateChange != null)
|
if (ServerStateChange != null)
|
||||||
ServerStateChange(this, new DynamicTCPServerStateChangedEventArgs(this, Secure));
|
ServerStateChange(this, new DynamicTCPServerStateChangedEventArgs(this, Secure));
|
||||||
|
ServerStopped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DisconnectAllClients()
|
public void DisconnectAllClients()
|
||||||
{
|
{
|
||||||
|
Debug.Console(0, "Disconnecting All Clients");
|
||||||
if (SecureServer != null && SecureServer.NumberOfClientsConnected > 0)
|
if (SecureServer != null && SecureServer.NumberOfClientsConnected > 0)
|
||||||
SecureServer.DisconnectAll();
|
SecureServer.DisconnectAll();
|
||||||
if (UnsecureServer != null && UnsecureServer.NumberOfClientsConnected > 0)
|
if (UnsecureServer != null && UnsecureServer.NumberOfClientsConnected > 0)
|
||||||
UnsecureServer.DisconnectAll();
|
UnsecureServer.DisconnectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void BroadcastText(string text)
|
||||||
|
{
|
||||||
|
if (ConnectedClientsIndexes.Count > 0)
|
||||||
|
{
|
||||||
|
if (Secure && SecureServer != null)
|
||||||
|
{
|
||||||
|
foreach (uint i in ConnectedClientsIndexes)
|
||||||
|
{
|
||||||
|
byte[] b = Encoding.ASCII.GetBytes(text);
|
||||||
|
SecureServer.SendDataAsync(i, b, b.Length, SecureSendDataAsyncCallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!Secure && UnsecureServer != null)
|
||||||
|
{
|
||||||
|
foreach (uint i in ConnectedClientsIndexes)
|
||||||
|
{
|
||||||
|
byte[] b = Encoding.ASCII.GetBytes(text);
|
||||||
|
UnsecureServer.SendDataAsync(i, b, b.Length, UnsecureSendDataAsyncCallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Not sure this is useful in library, maybe Pro??
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text"></param>
|
||||||
|
/// <param name="clientIndex"></param>
|
||||||
|
public void SendTextToClient(string text, uint clientIndex)
|
||||||
|
{
|
||||||
|
if (Secure && SecureServer != null)
|
||||||
|
{
|
||||||
|
byte[] b = Encoding.ASCII.GetBytes(text);
|
||||||
|
SecureServer.SendDataAsync(clientIndex, b, b.Length, SecureSendDataAsyncCallback);
|
||||||
|
}
|
||||||
|
else if (!Secure && UnsecureServer != null)
|
||||||
|
{
|
||||||
|
byte[] b = Encoding.ASCII.GetBytes(text);
|
||||||
|
UnsecureServer.SendDataAsync(clientIndex, b, b.Length, UnsecureSendDataAsyncCallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods - Socket Status Changed Callbacks
|
||||||
|
void SecureServer_SocketStatusChange(SecureTCPServer mySecureTCPServer, uint clientIndex, SocketStatus serverSocketStatus)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "Client at {0} ServerSocketStatus {1}",
|
||||||
|
mySecureTCPServer.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex), serverSocketStatus.ToString());
|
||||||
|
if (mySecureTCPServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
|
{
|
||||||
|
if (RequiresPresharedKey && !WaitingForSharedKey.Contains(clientIndex))
|
||||||
|
WaitingForSharedKey.Add(clientIndex);
|
||||||
|
if (!ConnectedClientsIndexes.Contains(clientIndex))
|
||||||
|
ConnectedClientsIndexes.Add(clientIndex);
|
||||||
|
}
|
||||||
|
if (mySecureTCPServer.GetServerSocketStatusForSpecificClient(clientIndex) != SocketStatus.SOCKET_STATUS_CONNECTED && ConnectedClientsIndexes.Contains(clientIndex))
|
||||||
|
ConnectedClientsIndexes.Remove(clientIndex);
|
||||||
|
|
||||||
|
onConnectionChange();//Go to simpl and send the server and whether it is secure or not. Could check secure from Simpl+ but better to use the passed
|
||||||
|
//variable in case we need to use this in Pro. Simpl+ won't use arguments, will just check the uIsConnected Property. Currently Simpl+ is just going to report
|
||||||
|
//connected not reporting by client
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnsecureServer_SocketStatusChange(TCPServer mySecureTCPServer, uint clientIndex, SocketStatus serverSocketStatus)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "Client at {0} ServerSocketStatus {1}",
|
||||||
|
mySecureTCPServer.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex), serverSocketStatus.ToString());
|
||||||
|
if (mySecureTCPServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
|
{
|
||||||
|
if (RequiresPresharedKey && !WaitingForSharedKey.Contains(clientIndex))
|
||||||
|
WaitingForSharedKey.Add(clientIndex);
|
||||||
|
if (!ConnectedClientsIndexes.Contains(clientIndex))
|
||||||
|
ConnectedClientsIndexes.Add(clientIndex);
|
||||||
|
}
|
||||||
|
if (mySecureTCPServer.GetServerSocketStatusForSpecificClient(clientIndex) != SocketStatus.SOCKET_STATUS_CONNECTED && ConnectedClientsIndexes.Contains(clientIndex))
|
||||||
|
ConnectedClientsIndexes.Remove(clientIndex);
|
||||||
|
|
||||||
|
onConnectionChange();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods Connected Callbacks
|
||||||
|
void SecureConnectCallback(SecureTCPServer mySecureTCPServer, uint clientIndex)
|
||||||
|
{
|
||||||
|
if (mySecureTCPServer.ClientConnected(clientIndex))
|
||||||
|
{
|
||||||
|
if (RequiresPresharedKey)
|
||||||
|
{
|
||||||
|
byte[] b = Encoding.ASCII.GetBytes(SharedKey + "\n");
|
||||||
|
mySecureTCPServer.SendDataAsync(clientIndex, b, b.Length, SecureSendDataAsyncCallback);
|
||||||
|
Debug.Console(0, "Sent Shared Key to client at {0}", mySecureTCPServer.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex));
|
||||||
|
}
|
||||||
|
mySecureTCPServer.ReceiveDataAsync(clientIndex, SecureReceivedCallback);
|
||||||
|
if (mySecureTCPServer.State != ServerState.SERVER_LISTENING && MaxConnections > 1)
|
||||||
|
SecureServer.WaitForConnectionAsync(IPAddress.Any, SecureConnectCallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnsecureConnectCallback(TCPServer myTCPServer, uint clientIndex)
|
||||||
|
{
|
||||||
|
if (myTCPServer.ClientConnected(clientIndex))
|
||||||
|
{
|
||||||
|
Debug.Console(0, "Connected to client at {0}", myTCPServer.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex));
|
||||||
|
myTCPServer.ReceiveDataAsync(clientIndex, UnsecureReceivedCallback);
|
||||||
|
}
|
||||||
|
if (myTCPServer.State != ServerState.SERVER_LISTENING && MaxConnections > 1)
|
||||||
|
UnsecureServer.WaitForConnectionAsync(IPAddress.Any, UnsecureConnectCallback);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods - Send/Receive Callbacks
|
||||||
|
void SecureSendDataAsyncCallback(SecureTCPServer mySecureTCPServer, uint clientIndex, int numberOfBytesSent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnsecureSendDataAsyncCallback(TCPServer myTCPServer, uint clientIndex, int numberOfBytesSent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SecureReceivedCallback(SecureTCPServer mySecureTCPServer, uint clientIndex, int numberOfBytesReceived)
|
||||||
|
{
|
||||||
|
if (numberOfBytesReceived > 0)
|
||||||
|
{
|
||||||
|
string received = "Nothing";
|
||||||
|
byte[] bytes = mySecureTCPServer.GetIncomingDataBufferForSpecificClient(clientIndex);
|
||||||
|
received = System.Text.Encoding.ASCII.GetString(bytes, 0, numberOfBytesReceived);
|
||||||
|
Debug.Console(0, "Secure Server Listening on Port: {0}, client IP: {1}, NumberOfBytesReceived: {2}, Received: {3}\r\n",
|
||||||
|
mySecureTCPServer.PortNumber, mySecureTCPServer.AddressServerAcceptedConnectionFrom, numberOfBytesReceived, received);
|
||||||
|
if (WaitingForSharedKey.Contains(clientIndex))
|
||||||
|
{
|
||||||
|
received = received.Replace("\r", "");
|
||||||
|
received = received.Replace("\n", "");
|
||||||
|
if (received != SharedKey)
|
||||||
|
{
|
||||||
|
byte[] b = Encoding.ASCII.GetBytes("Shared key did not match server. Disconnecting");
|
||||||
|
Debug.Console(0, "Client at index {0} Shared key did not match the server, disconnecting client", clientIndex);
|
||||||
|
ErrorLog.Error("Client at index {0} Shared key did not match the server, disconnecting client", clientIndex);
|
||||||
|
mySecureTCPServer.SendDataAsync(clientIndex, b, b.Length, null);
|
||||||
|
mySecureTCPServer.Disconnect(clientIndex);
|
||||||
|
}
|
||||||
|
if (mySecureTCPServer.NumberOfClientsConnected > 0)
|
||||||
|
mySecureTCPServer.ReceiveDataAsync(SecureReceivedCallback);
|
||||||
|
WaitingForSharedKey.Remove(clientIndex);
|
||||||
|
byte[] skResponse = Encoding.ASCII.GetBytes("Shared Key Match, Connected and ready for communication");
|
||||||
|
mySecureTCPServer.SendDataAsync(clientIndex, skResponse, skResponse.Length, null);
|
||||||
|
mySecureTCPServer.ReceiveDataAsync(SecureReceivedCallback);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
onTextReceived(received);
|
||||||
|
mySecureTCPServer.ReceiveDataAsync(SecureReceivedCallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mySecureTCPServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
|
mySecureTCPServer.ReceiveDataAsync(clientIndex, SecureReceivedCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnsecureReceivedCallback(TCPServer myTCPServer, uint clientIndex, int numberOfBytesReceived)
|
||||||
|
{
|
||||||
|
if (numberOfBytesReceived > 0)
|
||||||
|
{
|
||||||
|
string received = "Nothing";
|
||||||
|
byte[] bytes = myTCPServer.GetIncomingDataBufferForSpecificClient(clientIndex);
|
||||||
|
received = System.Text.Encoding.ASCII.GetString(bytes, 0, numberOfBytesReceived);
|
||||||
|
Debug.Console(0, "Unsecure Server Listening on Port: {0}, client IP: {1}, NumberOfBytesReceived: {2}, Received: {3}\r\n",
|
||||||
|
myTCPServer.PortNumber, myTCPServer.AddressServerAcceptedConnectionFrom, numberOfBytesReceived, received);
|
||||||
|
onTextReceived(received);
|
||||||
|
myTCPServer.ReceiveDataAsync(UnsecureReceivedCallback);
|
||||||
|
}
|
||||||
|
if (myTCPServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
|
myTCPServer.ReceiveDataAsync(clientIndex, UnsecureReceivedCallback);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods - EventHelper
|
||||||
void onConnectionChange()
|
void onConnectionChange()
|
||||||
{
|
{
|
||||||
var handler = ClientConnectionChange;
|
var handler = ClientConnectionChange;
|
||||||
@@ -267,26 +496,12 @@ namespace PepperDash_Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SecureServer_SocketStatusChange(SecureTCPServer mySecureTCPServer, uint clientIndex, SocketStatus serverSocketStatus)
|
void onTextReceived(string text)
|
||||||
{
|
{
|
||||||
onConnectionChange();//Go to simpl and send the server and whether it is secure or not. Could check secure from Simpl+ but better to use the passed
|
var handler = TextReceived;
|
||||||
//variable in case we need to use this in Pro. Simpl+ won't use arguments, will just check the uIsConnected Property. Currently Simpl+ is just going to report
|
if (handler != null)
|
||||||
//connected not reporting by client
|
TextReceived(this, new GenericCommMethodReceiveTextArgs(text));
|
||||||
}
|
|
||||||
|
|
||||||
void UnsecureServer_SocketStatusChange(TCPServer mySecureTCPServer, uint clientIndex, SocketStatus serverSocketStatus)
|
|
||||||
{
|
|
||||||
onConnectionChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SecureConnectCallback(SecureTCPServer mySecureTCPServer, uint clientIndex)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void UnsecureConnectCallback(TCPServer myTCPServer, uint clientIndex)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
Binary file not shown.
@@ -10,8 +10,8 @@
|
|||||||
<ArchiveName />
|
<ArchiveName />
|
||||||
</RequiredInfo>
|
</RequiredInfo>
|
||||||
<OptionalInfo>
|
<OptionalInfo>
|
||||||
<CompiledOn>3/14/2017 6:24:05 PM</CompiledOn>
|
<CompiledOn>3/15/2017 12:09:01 AM</CompiledOn>
|
||||||
<CompilerRev>1.0.6282.31321</CompilerRev>
|
<CompilerRev>1.0.6282.41670</CompilerRev>
|
||||||
</OptionalInfo>
|
</OptionalInfo>
|
||||||
<Plugin>
|
<Plugin>
|
||||||
<Version>Crestron.SIMPLSharp, Version=2.0.52.0, Culture=neutral, PublicKeyToken=812d080f93e2de10</Version>
|
<Version>Crestron.SIMPLSharp, Version=2.0.52.0, Culture=neutral, PublicKeyToken=812d080f93e2de10</Version>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,4 @@
|
|||||||
MainAssembly=PepperDash_Core.dll:513456572aabc0b1fbd5122dbfb691e5
|
MainAssembly=PepperDash_Core.dll:5c64dc849bf12d4e264b1963b820aee1
|
||||||
MainAssemblyMinFirmwareVersion=1.007.0017
|
MainAssemblyMinFirmwareVersion=1.007.0017
|
||||||
MainAssemblyResource=SimplSharpData.dat:315526abf906cded47fb0c7510266a7e
|
MainAssemblyResource=SimplSharpData.dat:315526abf906cded47fb0c7510266a7e
|
||||||
ü
|
ü
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user