Skip to content

Commit

Permalink
Add server port selection
Browse files Browse the repository at this point in the history
  • Loading branch information
EarToEarOak committed Feb 10, 2017
1 parent 52a1366 commit 618ce23
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 26 deletions.
36 changes: 30 additions & 6 deletions NetRemote/ControlPanel.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 11 additions & 14 deletions NetRemote/ControlPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SDRSharp Net Remote
http://eartoearoak.com/software/sdrsharp-net-remote
Copyright 2014 - 2015 Al Brown
Copyright 2014 - 2017 Al Brown
A network remote control plugin for SDRSharp
Expand Down Expand Up @@ -32,11 +32,13 @@ namespace SDRSharp.NetRemote
{
public partial class ControlPanel : UserControl
{
private const string _settingNotFirstRun = "netRemoteNotFirstRun";
private const string _settingServerEn = "netRemoteServerEnable";
private const string _settingServerPort = "netRemoteServerPort";
private const string _settingSerialEn = "netRemoteSerialEnable";
private const string _settingSerialPort = "netRemoteSerialPort";

private const int PORT = 3382;

private ISharpControl _control;

private Thread _threadServer;
Expand All @@ -52,17 +54,11 @@ public ControlPanel(ISharpControl control)
_parser = new Parser(control);
_control = control;

if (!Utils.GetBooleanSetting(_settingNotFirstRun))
{
checkNetwork.Checked = true;
checkSerial.Checked = true;
}
else
{
checkNetwork.Checked = Utils.GetBooleanSetting(_settingServerEn);
checkSerial.Checked = Utils.GetBooleanSetting(_settingSerialEn);
}
checkNetwork.Checked = Utils.GetBooleanSetting(_settingServerEn, true);
numPort.Value = Utils.GetIntSetting(_settingServerPort, PORT);
numPort.Enabled = !checkNetwork.Checked;

checkSerial.Checked = Utils.GetBooleanSetting(_settingSerialEn, true);
string[] ports = Serial.GetPorts();
if (ports.Length > 0)
{
Expand All @@ -84,8 +80,8 @@ public ControlPanel(ISharpControl control)

public void Close()
{
Utils.SaveSetting(_settingNotFirstRun, true);
Utils.SaveSetting(_settingServerEn, checkNetwork.Checked);
Utils.SaveSetting(_settingServerPort, numPort.Value);
Utils.SaveSetting(_settingSerialEn, checkSerial.Checked);
Utils.SaveSetting(_settingSerialPort, comboSerial.SelectedItem);

Expand All @@ -101,7 +97,7 @@ private void ServerControl()
{
if (_threadServer == null)
{
_server = new Server(_parser);
_server = new Server(_parser, (int)numPort.Value);
_server.ServerError += OnServerError;
_threadServer = new Thread(new ThreadStart(_server.Start));
_threadServer.Start();
Expand Down Expand Up @@ -143,6 +139,7 @@ private void SerialControl()

private void CheckChangedNetwork(object sender, EventArgs e)
{
numPort.Enabled = !checkNetwork.Checked;
ServerControl();
}

Expand Down
4 changes: 2 additions & 2 deletions NetRemote/ControlPanel.resx
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
9 changes: 5 additions & 4 deletions NetRemote/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SDRSharp Net Remote
http://eartoearoak.com/software/sdrsharp-net-remote
Copyright 2014 - 2015 Al Brown
Copyright 2014 - 2017 Al Brown
A network remote control plugin for SDRSharp
Expand Down Expand Up @@ -44,7 +44,6 @@ class Server
{
public event EventHandler ServerError;

private const int PORT = 3382;
private const int MAX_CLIENTS = 4;

private ManualResetEvent _signal = new ManualResetEvent(false);
Expand All @@ -53,18 +52,20 @@ class Server
private List<Client> clients = new List<Client>();
private volatile bool _cancel = false;
private Parser _parser;
private int _port;

private byte[] warnMaxClients = Encoding.ASCII.GetBytes(
"Too many connections");

public Server(Parser parser)
public Server(Parser parser, int port)
{
_parser = parser;
_port = port;
}

public void Start()
{
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, PORT);
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, _port);
Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);

Expand Down

0 comments on commit 618ce23

Please sign in to comment.