diff --git a/README.md b/README.md
index fe2d810..d34fbe1 100644
--- a/README.md
+++ b/README.md
@@ -36,7 +36,8 @@ This library provides a lightweight, multi-threaded HTTP/HTTPS WebServer for .NE
Using the Web Server is very straight forward and supports event based calls.
```csharp
-// You need to be connected to a wifi or ethernet connection with a proper IP Address
+// You need to be connected to a Wi-Fi or ethernet connection with a proper IP Address
+// Optionally you can pass a parameter with the IP address for the server to bind to
using (WebServer server = new WebServer(80, HttpProtocol.Http))
{
diff --git a/nanoFramework.WebServer/WebServer.cs b/nanoFramework.WebServer/WebServer.cs
index f552e22..c75abb4 100644
--- a/nanoFramework.WebServer/WebServer.cs
+++ b/nanoFramework.WebServer/WebServer.cs
@@ -263,7 +263,11 @@ public static UrlParameter[] ExtractRouteParameters(string route, string rawUrl,
///
/// Port number to listen on.
/// version to use with web server.
- public WebServer(int port, HttpProtocol protocol) : this(port, protocol, null)
+ /// IP address to bind to. If null, the server will bind to the default network interface.
+ public WebServer(
+ int port,
+ HttpProtocol protocol,
+ IPAddress address) : this(port, protocol, address, null)
{ }
///
@@ -272,14 +276,38 @@ public WebServer(int port, HttpProtocol protocol) : this(port, protocol, null)
/// Port number to listen on.
/// version to use with web server.
/// Controllers to use with this web server.
- public WebServer(int port, HttpProtocol protocol, Type[] controllers)
+ public WebServer(
+ int port,
+ HttpProtocol protocol,
+ Type[] controllers) : this(port, protocol, null, controllers)
+ { }
+
+ ///
+ /// Instantiates a new web server.
+ ///
+ /// Port number to listen on.
+ /// version to use with web server.
+ /// IP address to bind to. If , will bind to default address.
+ /// Controllers to use with this web server.
+ public WebServer(
+ int port,
+ HttpProtocol protocol,
+ IPAddress address,
+ Type[] controllers)
{
_callbackRoutes = new ArrayList();
+
RegisterControllers(controllers);
+
Protocol = protocol;
Port = port;
+
string prefix = Protocol == HttpProtocol.Http ? "http" : "https";
- _listener = new HttpListener(prefix, port);
+
+ _listener = new HttpListener(
+ prefix,
+ port,
+ address);
}
private void RegisterControllers(Type[] controllers)