Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
34 changes: 31 additions & 3 deletions nanoFramework.WebServer/WebServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ public static UrlParameter[] ExtractRouteParameters(string route, string rawUrl,
/// </summary>
/// <param name="port">Port number to listen on.</param>
/// <param name="protocol"><see cref="HttpProtocol"/> version to use with web server.</param>
public WebServer(int port, HttpProtocol protocol) : this(port, protocol, null)
/// <param name="address">IP address to bind to. If <c>null</c>, the server will bind to the default network interface.</param>
public WebServer(
int port,
HttpProtocol protocol,
IPAddress address) : this(port, protocol, address, null)
{ }

/// <summary>
Expand All @@ -272,14 +276,38 @@ public WebServer(int port, HttpProtocol protocol) : this(port, protocol, null)
/// <param name="port">Port number to listen on.</param>
/// <param name="protocol"><see cref="HttpProtocol"/> version to use with web server.</param>
/// <param name="controllers">Controllers to use with this web server.</param>
public WebServer(int port, HttpProtocol protocol, Type[] controllers)
public WebServer(
int port,
HttpProtocol protocol,
Type[] controllers) : this(port, protocol, null, controllers)
{ }

/// <summary>
/// Instantiates a new web server.
/// </summary>
/// <param name="port">Port number to listen on.</param>
/// <param name="protocol"><see cref="HttpProtocol"/> version to use with web server.</param>
/// <param name="address">IP address to bind to. If <see langword="null"/>, will bind to default address.</param>
/// <param name="controllers">Controllers to use with this web server.</param>
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)
Expand Down