diff --git a/NetRemote/ControlPanel.cs b/NetRemote/ControlPanel.cs index 4105506..a664b5b 100644 --- a/NetRemote/ControlPanel.cs +++ b/NetRemote/ControlPanel.cs @@ -102,6 +102,7 @@ private void ServerControl() if (_threadServer == null) { _server = new Server(_parser); + _server.ServerError += OnServerError; _threadServer = new Thread(new ThreadStart(_server.Start)); _threadServer.Start(); } @@ -156,5 +157,11 @@ private void OnSerialError(object sender, EventArgs e) _threadSerial = null; checkSerial.Checked = false; } + + private void OnServerError(object sender, EventArgs e) + { + _threadServer = null; + checkNetwork.Checked = false; + } } } diff --git a/NetRemote/Server.cs b/NetRemote/Server.cs index 5c70f18..658b79d 100644 --- a/NetRemote/Server.cs +++ b/NetRemote/Server.cs @@ -42,6 +42,8 @@ namespace SDRSharp.NetRemote class Server { + public event EventHandler ServerError; + private const int PORT = 3382; private const int MAX_CLIENTS = 4; @@ -86,10 +88,13 @@ public void Start() } catch (SocketException ex) { + OnServerError(); + if (socket.IsBound) socket.Shutdown(SocketShutdown.Both); - MessageBox.Show(ex.Message, Info.Title(), + string msg = "Network Error:\n" + ex.Message; + MessageBox.Show(msg, Info.Title(), MessageBoxButtons.OK, MessageBoxIcon.Error); } finally @@ -251,6 +256,15 @@ private void OnTimerAlive(object source, ElapsedEventArgs e) ClientRemove(client); } } + + protected virtual void OnServerError() + { + EventHandler handler = ServerError; + if (handler != null) + { + handler(this, EventArgs.Empty); + } + } }