diff --git a/MiniWebServer/MiniWebServer/WebListener.cs b/MiniWebServer/MiniWebServer/WebListener.cs index ee498aa..e2b8199 100644 --- a/MiniWebServer/MiniWebServer/WebListener.cs +++ b/MiniWebServer/MiniWebServer/WebListener.cs @@ -28,12 +28,18 @@ public WebListener(string prefix) listener.Prefixes.Add(prefix); } + public void SetPrefix(string prefix) + { + listener.Prefixes.Clear(); + listener.Prefixes.Add(prefix); + } + public void Start() { listenerThread = new Thread(() => { listener.Start(); - Log.Info($"Http Listener started - Prefix: {listener.Prefixes.First()}"); + Log.Info($"Http listener started - Prefix: {listener.Prefixes.First()}."); while (listener.IsListening) Listen(); @@ -43,7 +49,7 @@ public void Start() listenerThread.Start(); if (WebServerStarted.GetInvocationList().Count() > 0) - WebServerStarted.Invoke(); + WebServerStarted.Invoke(); } public void Listen() @@ -76,6 +82,7 @@ public void Stop() listenerThread.Interrupt(); listenerThread.Abort(); listenerThread = null; + Log.Info("Stopped Http Listener."); } catch (ThreadAbortException e) { diff --git a/MiniWebServer/MiniWebServer/WebServer.cs b/MiniWebServer/MiniWebServer/WebServer.cs index 7297462..d52394a 100644 --- a/MiniWebServer/MiniWebServer/WebServer.cs +++ b/MiniWebServer/MiniWebServer/WebServer.cs @@ -18,7 +18,11 @@ public class WebServer private void WebListener_WebServerStarted() => ServerInterface.SetServerStatus(true); - public void Start() => webListener.Start(); + public void Start() + { + webListener.SetPrefix($"http://*:{ServerInterface.GetPortNumber()}/"); + webListener.Start(); + } public void Stop() => webListener.Stop(); @@ -28,7 +32,7 @@ public WebServer(WebServerInterface serverInterface) return; ServerInterface = serverInterface; - webListener = new WebListener("http://*:" + ServerInterface.GetPortNumber + "/"); + webListener = new WebListener($"http://*:{ServerInterface.GetPortNumber()}/"); webListener.HttpCall += WebListener_HttpCall; webListener.WebServerStarted += WebListener_WebServerStarted; webListener.WebServerStopped += WebListener_WebServerStopped; diff --git a/MiniWebServer/MiniWebServer/WebServerInterface.cs b/MiniWebServer/MiniWebServer/WebServerInterface.cs index c8158f3..8a4d342 100644 --- a/MiniWebServer/MiniWebServer/WebServerInterface.cs +++ b/MiniWebServer/MiniWebServer/WebServerInterface.cs @@ -15,7 +15,6 @@ namespace MiniWebServer { public partial class WebServerInterface : Form { - public int GetPortNumber { get { return (int)webServerPort.Value; } } private WebServer webServer; public WebServerInterface() @@ -23,6 +22,11 @@ public WebServerInterface() InitializeComponent(); } + public int GetPortNumber() + { + return (int)webServerPort.Value; + } + public void SetServerStatus(bool online) { serverStatusLabel.Text = online ? "Online" : "Offline";