My Project
|
Provides a simple HTTP server. More...
Public Member Functions | |
HttpServer () | |
Initializes a new instance of the HttpServer class. | |
HttpServer (int port) | |
Initializes a new instance of the HttpServer class with the specified port. | |
HttpServer (string url) | |
Initializes a new instance of the HttpServer class with the specified URL. | |
HttpServer (int port, bool secure) | |
Initializes a new instance of the HttpServer class with the specified port and boolean if secure or not. | |
HttpServer (System.Net.IPAddress address, int port) | |
Initializes a new instance of the HttpServer class with the specified IP address and port. | |
HttpServer (System.Net.IPAddress address, int port, bool secure) | |
Initializes a new instance of the HttpServer class with the specified IP address, port, and boolean if secure or not. | |
void | AddWebSocketService< TBehavior > (string path) |
Adds a WebSocket service with the specified behavior and path. | |
void | AddWebSocketService< TBehavior > (string path, Action< TBehavior > initializer) |
Adds a WebSocket service with the specified behavior, path, and delegate. | |
bool | RemoveWebSocketService (string path) |
Removes a WebSocket service with the specified path. | |
void | Start () |
Starts receiving incoming requests. | |
void | Stop () |
Stops receiving incoming requests. | |
Properties | |
System.Net.IPAddress | Address [get] |
Gets the IP address of the server. | |
AuthenticationSchemes | AuthenticationSchemes [get, set] |
Gets or sets the scheme used to authenticate the clients. | |
string | DocumentRootPath [get, set] |
Gets or sets the path to the document folder of the server. | |
bool | IsListening [get] |
Gets a value indicating whether the server has started. | |
bool | IsSecure [get] |
Gets a value indicating whether secure connections are provided. | |
bool | KeepClean [get, set] |
Gets or sets a value indicating whether the server cleans up the inactive sessions periodically. | |
Logger | Log [get] |
Gets the logging function for the server. | |
int | Port [get] |
Gets the port of the server. | |
string | Realm [get, set] |
Gets or sets the name of the realm associated with the server. | |
bool | ReuseAddress [get, set] |
Gets or sets a value indicating whether the server is allowed to be bound to an address that is already in use. | |
ServerSslConfiguration | SslConfiguration [get] |
Gets the configuration for secure connection. | |
Func< IIdentity, NetworkCredential > | UserCredentialsFinder [get, set] |
Gets or sets the delegate used to find the credentials for an identity. | |
TimeSpan | WaitTime [get, set] |
Gets or sets the time to wait for the response to the WebSocket Ping or Close. | |
WebSocketServiceManager | WebSocketServices [get] |
Gets the management function for the WebSocket services provided by the server. | |
Events | |
EventHandler< HttpRequestEventArgs > | OnConnect |
Occurs when the server receives an HTTP CONNECT request. | |
EventHandler< HttpRequestEventArgs > | OnDelete |
Occurs when the server receives an HTTP DELETE request. | |
EventHandler< HttpRequestEventArgs > | OnGet |
Occurs when the server receives an HTTP GET request. | |
EventHandler< HttpRequestEventArgs > | OnHead |
Occurs when the server receives an HTTP HEAD request. | |
EventHandler< HttpRequestEventArgs > | OnOptions |
Occurs when the server receives an HTTP OPTIONS request. | |
EventHandler< HttpRequestEventArgs > | OnPost |
Occurs when the server receives an HTTP POST request. | |
EventHandler< HttpRequestEventArgs > | OnPut |
Occurs when the server receives an HTTP PUT request. | |
EventHandler< HttpRequestEventArgs > | OnTrace |
Occurs when the server receives an HTTP TRACE request. | |
Provides a simple HTTP server.
The server supports HTTP/1.1 version request and response.
And the server allows to accept WebSocket handshake requests.
This class can provide multiple WebSocket services.
|
inline |
Initializes a new instance of the HttpServer class.
The new instance listens for incoming requests on System.Net.IPAddress.Any and port 80.
|
inline |
Initializes a new instance of the HttpServer class with the specified port.
The new instance listens for incoming requests on System.Net.IPAddress.Any and port .
It provides secure connections if port is 443.
port | An int that specifies the number of the port on which to listen. |
ArgumentOutOfRangeException | port is less than 1 or greater than 65535. |
|
inline |
Initializes a new instance of the HttpServer class with the specified URL.
The new instance listens for incoming requests on the IP address and port of url .
Either port 80 or 443 is used if url includes no port. Port 443 is used if the scheme of url is https; otherwise, port 80 is used.
The new instance provides secure connections if the scheme of url is https.
url | A string that specifies the HTTP URL of the server. |
ArgumentNullException | url is null . |
ArgumentException | url is an empty string. -or- url is invalid. |
|
inline |
Initializes a new instance of the HttpServer class with the specified port and boolean if secure or not.
The new instance listens for incoming requests on System.Net.IPAddress.Any and port .
port | An int that specifies the number of the port on which to listen. |
secure | A bool: true if the new instance provides secure connections; otherwise, false . |
ArgumentOutOfRangeException | port is less than 1 or greater than 65535. |
|
inline |
Initializes a new instance of the HttpServer class with the specified IP address and port.
The new instance listens for incoming requests on address and port .
It provides secure connections if port is 443.
address | A System.Net.IPAddress that specifies the local IP address on which to listen. |
port | An int that specifies the number of the port on which to listen. |
ArgumentNullException | address is null . |
ArgumentException | address is not a local IP address. |
ArgumentOutOfRangeException | port is less than 1 or greater than 65535. |
|
inline |
Initializes a new instance of the HttpServer class with the specified IP address, port, and boolean if secure or not.
The new instance listens for incoming requests on address and port .
address | A System.Net.IPAddress that specifies the local IP address on which to listen. |
port | An int that specifies the number of the port on which to listen. |
secure | A bool: true if the new instance provides secure connections; otherwise, false . |
ArgumentNullException | address is null . |
ArgumentException | address is not a local IP address. |
ArgumentOutOfRangeException | port is less than 1 or greater than 65535. |
|
inline |
Adds a WebSocket service with the specified behavior and path.
path | A string that specifies an absolute path to the service to add. / is trimmed from the end of the string if present. |
TBehavior | The type of the behavior for the service. It must inherit the WebSocketBehavior class. And also, it must have a public parameterless constructor. |
ArgumentNullException | path is null . |
ArgumentException | path is an empty string. -or- path is not an absolute path. -or- path includes either or both query and fragment components. -or- path is already in use. |
TBehavior | : | WebSocketBehavior | |
TBehavior | : | new |
|
inline |
Adds a WebSocket service with the specified behavior, path, and delegate.
path | A string that specifies an absolute path to the service to add. / is trimmed from the end of the string if present. |
initializer | An Action<TBehavior> delegate or null if not needed. The delegate invokes the method called when initializing a new session instance for the service. |
TBehavior | The type of the behavior for the service. It must inherit the WebSocketBehavior class. And also, it must have a public parameterless constructor. |
ArgumentNullException | path is null . |
ArgumentException | path is an empty string. -or- path is not an absolute path. -or- path includes either or both query and fragment components. -or- path is already in use. |
TBehavior | : | WebSocketBehavior | |
TBehavior | : | new |
|
inline |
Removes a WebSocket service with the specified path.
The service is stopped with close status 1001 (going away) if it has already started.
true
if the service is successfully found and removed; otherwise, false
. path | A string that specifies an absolute path to the service to remove. / is trimmed from the end of the string if present. |
ArgumentNullException | path is null . |
ArgumentException | path is an empty string. -or- path is not an absolute path. -or- path includes either or both query and fragment components. |
|
inline |
Starts receiving incoming requests.
This method does nothing if the server has already started or it is shutting down.
InvalidOperationException | There is no server certificate for secure connection. -or- The underlying HttpListener has failed to start. |
|
inline |
Stops receiving incoming requests.
This method does nothing if the server is not started, it is shutting down, or it has already stopped.
|
get |
Gets the IP address of the server.
A System.Net.IPAddress that represents the local IP address on which to listen for incoming requests.
|
getset |
Gets or sets the scheme used to authenticate the clients.
The set operation does nothing if the server has already started or it is shutting down.
One of the WebSocketSharp.Net.AuthenticationSchemes enum values.
It represents the scheme used to authenticate the clients.
The default value is WebSocketSharp.Net.AuthenticationSchemes.Anonymous.
|
getset |
Gets or sets the path to the document folder of the server.
'/' or '\' is trimmed from the end of the value if any.
The set operation does nothing if the server has already started or it is shutting down.
A string that represents a path to the folder from which to find the requested file.
The default value is "./Public".
ArgumentNullException | The value specified for a set operation is null . |
ArgumentException | The value specified for a set operation is an empty string. -or- The value specified for a set operation is an absolute root. -or- The value specified for a set operation is an invalid path string. |
|
get |
Gets a value indicating whether the server has started.
true
if the server has started; otherwise, false
.
|
get |
Gets a value indicating whether secure connections are provided.
true
if this instance provides secure connections; otherwise, false
.
|
getset |
Gets or sets a value indicating whether the server cleans up the inactive sessions periodically.
The set operation does nothing if the server has already started or it is shutting down.
true
if the server cleans up the inactive sessions every 60 seconds; otherwise, false
.
The default value is true
.
|
get |
Gets the logging function for the server.
The default logging level is LogLevel.Error.
A Logger that provides the logging function.
|
get |
Gets the port of the server.
An int that represents the number of the port on which to listen for incoming requests.
|
getset |
Gets or sets the name of the realm associated with the server.
"SECRET AREA" is used as the name of the realm if the value is null
or an empty string.
The set operation does nothing if the server has already started or it is shutting down.
A string that represents the name of the realm or null
.
The default value is null
.
|
getset |
Gets or sets a value indicating whether the server is allowed to be bound to an address that is already in use.
You should set this property to true
if you would like to resolve to wait for socket in TIME_WAIT state.
The set operation does nothing if the server has already started or it is shutting down.
true
if the server is allowed to be bound to an address that is already in use; otherwise, false
.
The default value is false
.
|
get |
Gets the configuration for secure connection.
The configuration will be referenced when attempts to start, so it must be configured before the start method is called.
A ServerSslConfiguration that represents the configuration used to provide secure connections.
InvalidOperationException | This server does not provide secure connections. |
|
getset |
Gets or sets the delegate used to find the credentials for an identity.
No credentials are found if the method invoked by the delegate returns null
or the value is null
.
The set operation does nothing if the server has already started or it is shutting down.
A Func<IIdentity, NetworkCredential>
delegate or null
if not needed.
The delegate invokes the method called for finding the credentials used to authenticate a client.
The default value is null
.
|
getset |
Gets or sets the time to wait for the response to the WebSocket Ping or Close.
The set operation does nothing if the server has already started or it is shutting down.
A TimeSpan to wait for the response.
The default value is the same as 1 second.
ArgumentOutOfRangeException | The value specified for a set operation is zero or less. |
|
get |
Gets the management function for the WebSocket services provided by the server.
A WebSocketServiceManager that manages the WebSocket services provided by the server.