Class HttpServer
A simple HTTP server.
[CLSCompliant(false)]
[MustDisposeResource]
public abstract class HttpServer
- Inheritance
-
objectHttpServer
- 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
ushortThe TCP port to listen on;
0
to automatically pick free port.localOnly
booltrue
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()