Started class for server, but did not get far yet

This commit is contained in:
Joshua Gutenplan
2017-03-13 17:53:20 -07:00
parent 1227038b55
commit ac1166b0f8
13 changed files with 46 additions and 8 deletions

Binary file not shown.

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
namespace PepperDash_Core.Comm
{
public class DynamicTCPServer
{
public bool Secure { get; set; }
public ushort uSecure
{
set
{
if (value == 1)
Secure = true;
else if (value == 0)
Secure = false;
}
}
}
}

View File

@@ -47,6 +47,19 @@ namespace SecureTCP.SecureTCP.Client
set { Port = Convert.ToInt32(value); } set { Port = Convert.ToInt32(value); }
} }
public bool RequiresPresharedKey { get; set; }
public ushort uRequiresPresharedKey
{
set
{
if (value == 1)
RequiresPresharedKey = true;
else
RequiresPresharedKey = false;
}
}
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
@@ -218,7 +231,7 @@ namespace SecureTCP.SecureTCP.Client
Debug.Console(1, Debug.ErrorLogLevel.Warning, "GenericSecureTcpClient '{0}': Invalid port", Key); Debug.Console(1, Debug.ErrorLogLevel.Warning, "GenericSecureTcpClient '{0}': Invalid port", Key);
return; return;
} }
if (string.IsNullOrEmpty(SharedKey)) if (string.IsNullOrEmpty(SharedKey) && RequiresPresharedKey)
{ {
Debug.Console(1, Debug.ErrorLogLevel.Warning, "GenericSecureTcpClient '{0}': No Shared Key set", Key); Debug.Console(1, Debug.ErrorLogLevel.Warning, "GenericSecureTcpClient '{0}': No Shared Key set", Key);
return; return;
@@ -230,7 +243,8 @@ namespace SecureTCP.SecureTCP.Client
try try
{ {
DisconnectCalledByUser = false; DisconnectCalledByUser = false;
WaitingForSharedKeyResponse = true; if(RequiresPresharedKey)
WaitingForSharedKeyResponse = true;
SocketErrorCodes error = Client.ConnectToServer(); SocketErrorCodes error = Client.ConnectToServer();
} }
catch (Exception ex) catch (Exception ex)
@@ -265,7 +279,7 @@ namespace SecureTCP.SecureTCP.Client
{ {
var bytes = client.IncomingDataBuffer.Take(numBytes).ToArray(); var bytes = client.IncomingDataBuffer.Take(numBytes).ToArray();
var str = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length); var str = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length);
if (WaitingForSharedKeyResponse) if (WaitingForSharedKeyResponse && RequiresPresharedKey)
{ {
if (str != (SharedKey + "\n")) if (str != (SharedKey + "\n"))
{ {
@@ -308,8 +322,6 @@ namespace SecureTCP.SecureTCP.Client
public void SendBytes(byte[] bytes) public void SendBytes(byte[] bytes)
{ {
//if (Debug.Level == 2)
// Debug.Console(2, this, "Sending {0} bytes: '{1}'", bytes.Length, ComTextHelper.GetEscapedText(bytes));
Client.SendData(bytes, bytes.Length); Client.SendData(bytes, bytes.Length);
} }

View File

@@ -64,6 +64,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="CommunicationExtras.cs" /> <Compile Include="CommunicationExtras.cs" />
<Compile Include="Comm\ControlPropertiesConfig.cs" /> <Compile Include="Comm\ControlPropertiesConfig.cs" />
<Compile Include="Comm\DynamicTCPServer.cs" />
<Compile Include="Comm\eControlMethods.cs" /> <Compile Include="Comm\eControlMethods.cs" />
<Compile Include="Comm\FINISH CommStatic.cs" /> <Compile Include="Comm\FINISH CommStatic.cs" />
<Compile Include="Comm\CommunicationGather.cs" /> <Compile Include="Comm\CommunicationGather.cs" />

View File

@@ -10,8 +10,8 @@
<ArchiveName /> <ArchiveName />
</RequiredInfo> </RequiredInfo>
<OptionalInfo> <OptionalInfo>
<CompiledOn>3/10/2017 6:22:56 PM</CompiledOn> <CompiledOn>3/13/2017 5:30:30 PM</CompiledOn>
<CompilerRev>1.0.6278.33087</CompilerRev> <CompilerRev>1.0.6281.19814</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>

View File

@@ -1,4 +1,4 @@
MainAssembly=PepperDash_Core.dll:79619d005133babcf49ba6c3bbc3de28 MainAssembly=PepperDash_Core.dll:bbf10e2b8fa14d4d571eeafc3bffb1a3
MainAssemblyMinFirmwareVersion=1.007.0017 MainAssemblyMinFirmwareVersion=1.007.0017
MainAssemblyResource=SimplSharpData.dat:315526abf906cded47fb0c7510266a7e MainAssemblyResource=SimplSharpData.dat:315526abf906cded47fb0c7510266a7e
ü ü