C# Класс Woopsa.WebServer

Provides a simple Web Server

A Web server can be single-threaded or multi-threaded. When it is single-threaded, only a single thread handles all incoming requests. This means that browsers will have to wait until the response is fully delivered before making the next request. This also means that the Connection: Keep-Alive HTTP mechanism cannot be used.

If the server is multi-threaded, then a ThreadPool is used to handle client requests and the Connection: Keep-Alive mechanism is thus supported. This makes page loading times significantly faster, as the browser doesn't need to close and re-open a TCP connection for every resource it fetches.

This Web Server is not meant to replace complex servers such as Apache, NGinx or ISS. It does not support more complex mechanisms such as: POST requests encoded with multipart/form-data (file uploads) HTTP Methods other than POST, GET, PUT, DELETE (must be handled manually)
Наследование: IDisposable
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
Dispose ( ) : void
HTTPResponse_Error ( object sender, HTTPResponseErrorEventArgs e ) : void
Shutdown ( ) : void

Shutdowns the server and stops listening for TCP connexions. At this point, the server becomes completely unreachable. It cannot be restarted.

Start ( ) : void

Starts listening on the TCP socket and initiates the routing mechanism. At this point, the server become reachable by any client.

WebServer ( int port = DefaultPortHttp, int threadPoolSize = CustomThreadPool.DefaultThreadPoolSize, ThreadPriority priority = DefaultThreadPriority ) : System

Creates a WebServer that runs on the specified port and can be multithreaded

A server must be multithreaded in order to use the Keep-Alive HTTP mechanism.

Защищенные методы

Метод Описание
Dispose ( bool disposing ) : void
OnError ( EventArgs args ) : void
OnLog ( HTTPRequest request, HTTPResponse response ) : void

Приватные методы

Метод Описание
ExtractPOST ( HTTPRequest request, StreamReader reader, Encoding clientEncoding ) : void
ExtractQuery ( HTTPRequest request, Encoding clientEncoding ) : void
FillHeaders ( HTTPRequest request, StreamReader reader ) : void
HandleClient ( TcpClient client ) : void
InferEncoding ( HTTPRequest request ) : Encoding
Listen ( ) : void
_routeSolver_Error ( object sender, RoutingErrorEventArgs e ) : void

Описание методов

Dispose() публичный Метод

public Dispose ( ) : void
Результат void

Dispose() защищенный Метод

protected Dispose ( bool disposing ) : void
disposing bool
Результат void

HTTPResponse_Error() публичный Метод

public HTTPResponse_Error ( object sender, HTTPResponseErrorEventArgs e ) : void
sender object
e HTTPResponseErrorEventArgs
Результат void

OnError() защищенный Метод

protected OnError ( EventArgs args ) : void
args System.EventArgs
Результат void

OnLog() защищенный Метод

protected OnLog ( HTTPRequest request, HTTPResponse response ) : void
request HTTPRequest
response HTTPResponse
Результат void

Shutdown() публичный Метод

Shutdowns the server and stops listening for TCP connexions. At this point, the server becomes completely unreachable. It cannot be restarted.
public Shutdown ( ) : void
Результат void

Start() публичный Метод

Starts listening on the TCP socket and initiates the routing mechanism. At this point, the server become reachable by any client.
public Start ( ) : void
Результат void

WebServer() публичный Метод

Creates a WebServer that runs on the specified port and can be multithreaded
A server must be multithreaded in order to use the Keep-Alive HTTP mechanism.
public WebServer ( int port = DefaultPortHttp, int threadPoolSize = CustomThreadPool.DefaultThreadPoolSize, ThreadPriority priority = DefaultThreadPriority ) : System
port int /// The port on which to run the server (default 80) ///
threadPoolSize int /// The maximum number of threads to be created. /// CustomThreadPool.DefaultThreadPoolSize means use default operating system value. ///
priority ThreadPriority /// The priority of the web server threads. ///
Результат System