Table of Contents

TSocketHttpServer Class

Standalone HTTP server for Linux and Windows that listens on raw sockets, with optional TLS support.

Remarks

TSocketHttpServer runs an event loop thread (epoll on Linux, WSAPoll on Windows) that accepts connections and assembles request heads, so slow clients never occupy a worker thread. Complete requests are dispatched synchronously on a worker thread pool, which grows on demand -- see "WorkerThreads" -- so handlers that block on a database or on another server do not queue up behind each other. The public API mirrors THttpSysServer: register modules with AddModule, then call Start and Stop to control the server. Configuration properties must be set before starting the server. The server is functional on the Linux and Windows platforms. The class is declared on all platforms so its documentation is available everywhere, but creating an instance on any other platform raises an ESocketServerException. On Windows, THttpSysServer remains the recommended choice for high-load production servers (it is kernel-mode and supports port sharing); the socket server is useful when administrative URL reservations are not an option or when identical behavior across Windows and Linux is desired.

Syntax

Unit: Sparkle.Socket.Server

TSocketHttpServer = class(TObject);

Constants

Name Description
DefaultHeader​Read​Timeout Default value of the HeaderReadTimeout property, in milliseconds.
DefaultIoTimeout Default value of the ReadTimeout and WriteTimeout properties, in milliseconds.
DefaultKeepAlive​Timeout Default value of the KeepAliveTimeout property, in milliseconds.
DefaultListenBacklog Default value of the ListenBacklog property.
DefaultMaxConnections Default value of the MaxConnections property.
DefaultMaxQueued​Requests Default value of the MaxQueuedRequests property.

Constructors

Name Description
Create Creates a new server instance with no modules registered and all configuration properties set to their default values.

Methods

Name Description
AddModule Registers an HTTP server module to process the requests addressed to its base URI.
ReloadCertificates Re-reads the certificate files configured in Ssl and applies them to new connections, without dropping the listeners or established connections.
Start Starts the server: binds a listening socket for each port used by the registered modules and begins accepting connections.
Stop Stops the server: closes the listeners and all connections and waits for the worker threads to finish the requests being processed.

Properties

Name Description
Dispatcher The dispatcher that holds the registered modules and routes each incoming request to the module matching its URI.
HeaderReadTimeout Gets or sets the maximum time, in milliseconds, for a client to send the complete request head, counted from its first byte.
IsRunning Indicates whether the server is currently running.
KeepAliveTimeout Gets or sets the time, in milliseconds, an idle keep-alive connection is kept open.
Limits Protection limits enforced while parsing incoming requests.
ListenBacklog Gets or sets the backlog size of the listening sockets: the maximum number of pending connections not yet accepted by the server.
LogEngine Gets or sets the log engine that receives the server error and diagnostic messages.
MaxConnections Gets or sets the maximum number of simultaneous connections.
MaxQueuedRequests Gets or sets the maximum number of requests waiting for a worker thread.
MaxWorkerThreads Gets or sets the maximum number of worker threads the server may reach while requests wait for a worker.
ReadTimeout Gets or sets the timeout, in milliseconds, for reading the request body on a worker thread.
Ssl TLS settings used to serve modules registered with an https base URI.
WorkerThreads Gets or sets the minimum number of worker threads that process requests.
WriteTimeout Gets or sets the timeout, in milliseconds, for writing the response on a worker thread.