Table of Contents

Class HttpServer

Namespace
NanoByte.Common.Net
Assembly
NanoByte.Common.dll

A simple HTTP server.

[CLSCompliant(false)]
[MustDisposeResource]
public abstract class HttpServer
Inheritance
object
HttpServer
Derived
Extension Methods

Constructors

HttpServer(ushort, bool)

Gets ready to serve HTTP requests. Call StartHandlingRequests() after completing any additional setup.

protected HttpServer(ushort port = 0, bool localOnly = false)

Parameters

port ushort

The TCP port to listen on; 0 to automatically pick free port.

localOnly bool

true to only respond to requests from the local machine instead of the network.

Exceptions

WebException

Unable to serve on the specified port.

NotAdminException

Needs admin rights to serve HTTP requests.

Properties

Port

The TCP port the server is listing on.

public ushort Port { get; }

Property Value

ushort

Methods

Dispose()

Stops serving HTTP requests.

public virtual void Dispose()

HandleRequest(HttpListenerContext)

Handles a single HTTP request.

protected abstract void HandleRequest(HttpListenerContext context)

Parameters

context HttpListenerContext

StartHandlingRequests()

To be called by derived constructor when setup is complete.

protected void StartHandlingRequests()