From d2dc6ff959a903c915e4eefa140a974a00f0edd1 Mon Sep 17 00:00:00 2001 From: sta Date: Sun, 12 Jul 2015 16:56:02 +0900 Subject: [PATCH] Fix for pull request #115, added the Address property to the HttpServer class --- websocket-sharp/Server/HttpServer.cs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/websocket-sharp/Server/HttpServer.cs b/websocket-sharp/Server/HttpServer.cs index 1a0aac29..aa0a1234 100644 --- a/websocket-sharp/Server/HttpServer.cs +++ b/websocket-sharp/Server/HttpServer.cs @@ -60,6 +60,8 @@ namespace WebSocketSharp.Server { #region Private Fields + private System.Net.IPAddress _address; + private string _hostname; private HttpListener _listener; private Logger _logger; private int _port; @@ -83,7 +85,7 @@ namespace WebSocketSharp.Server /// public HttpServer () { - init ("*", 80, false); + init ("*", System.Net.IPAddress.Any, 80, false); } /// @@ -134,7 +136,7 @@ namespace WebSocketSharp.Server throw new ArgumentOutOfRangeException ( "port", "Not between 1 and 65535 inclusive: " + port); - init ("*", port, secure); + init ("*", System.Net.IPAddress.Any, port, secure); } /// @@ -210,13 +212,25 @@ namespace WebSocketSharp.Server throw new ArgumentOutOfRangeException ( "port", "Not between 1 and 65535 inclusive: " + port); - init (address.ToString (), port, secure); + init (null, address, port, secure); } #endregion #region Public Properties + /// + /// Gets the local IP address of the server. + /// + /// + /// A that represents the local IP address of the server. + /// + public System.Net.IPAddress Address { + get { + return _address; + } + } + /// /// Gets or sets the scheme used to authenticate the clients. /// @@ -559,14 +573,16 @@ namespace WebSocketSharp.Server return !(usr || port) ? "The secure connection requires a server certificate." : null; } - private void init (string hostname, int port, bool secure) + private void init (string hostname, System.Net.IPAddress address, int port, bool secure) { + _hostname = hostname ?? address.ToString (); + _address = address; _port = port; _secure = secure; _listener = new HttpListener (); _listener.Prefixes.Add ( - String.Format ("http{0}://{1}:{2}/", secure ? "s" : "", hostname, port)); + String.Format ("http{0}://{1}:{2}/", secure ? "s" : "", _hostname, port)); _logger = _listener.Log; _services = new WebSocketServiceManager (_logger);