vibe.http.websockets

Implements WebSocket support and fallbacks for older browsers.

Members

Aliases

WebSocketHandshakeDelegate
alias WebSocketHandshakeDelegate = void delegate(scope WebSocket) nothrow
Undocumented in source.

Classes

IncomingWebSocketMessage
class IncomingWebSocketMessage

Represents a single incoming WebSocket message as an InputStream.

OutgoingWebSocketMessage
class OutgoingWebSocketMessage

Represents a single outgoing WebSocket message as an OutputStream.

WebSocket
class WebSocket

Represents a single WebSocket connection.

WebSocketException
class WebSocketException

Exception thrown by vibe.http.websockets.

Enums

FrameOpcode
enum FrameOpcode

The Opcode is 4 bits, as defined in Section 5.2

WebSocketCloseReason
enum WebSocketCloseReason

Provides the reason that a websocket connection has closed.

Functions

closeReasonString
string closeReasonString(WebSocketCloseReason reason)
Undocumented in source. Be warned that the author may not have intended to support it.
connectWebSocket
WebSocket connectWebSocket(URL url, const(HTTPClientSettings) settings)
void connectWebSocket(URL url, WebSocketHandshakeDelegate del, const(HTTPClientSettings) settings)
void connectWebSocket(URL url, void delegate(scope WebSocket) @(system) del, const(HTTPClientSettings) settings)

Establishes a WebSocket connection at the specified endpoint.

connectWebSocket
void connectWebSocket(URL url, void delegate(scope WebSocket) @(system) nothrow del, const(HTTPClientSettings) settings)

Scheduled for deprecation - use a @safe callback instead.

connectWebSocket
void connectWebSocket(URL url, void delegate(scope WebSocket) @(safe) del, const(HTTPClientSettings) settings)

Scheduled for deprecation - use a nothrow callback instead.

connectWebSocketEx
WebSocket connectWebSocketEx(URL url, void delegate(scope HTTPClientRequest) @(safe) request_modifier, const(HTTPClientSettings) settings)
void connectWebSocketEx(URL url, void delegate(scope HTTPClientRequest) @(safe) request_modifier, WebSocketHandshakeDelegate del, const(HTTPClientSettings) settings)

Establishes a WebSocket connection at the specified endpoint.

handleWebSocket
void handleWebSocket(WebSocketHandshakeDelegate on_handshake, HTTPServerRequest req, HTTPServerResponse res)

Establishes a web socket conection and passes it to the on_handshake delegate.

handleWebSocket
void handleWebSocket(void delegate(scope WebSocket) @(system) nothrow on_handshake, HTTPServerRequest req, HTTPServerResponse res)

Scheduled for deprecation - use a @safe callback instead.

handleWebSocket
void handleWebSocket(void delegate(scope WebSocket) @(safe) on_handshake, HTTPServerRequest req, HTTPServerResponse res)
void handleWebSocket(void delegate(scope WebSocket) @(system) on_handshake, HTTPServerRequest req, HTTPServerResponse res)

Scheduled for deprecation - use a nothrow callback instead.

handleWebSockets
HTTPServerRequestDelegateS handleWebSockets(void function(scope WebSocket) @(safe) nothrow on_handshake)
HTTPServerRequestDelegateS handleWebSockets(WebSocketHandshakeDelegate on_handshake)

Returns a HTTP request handler that establishes web socket conections.

handleWebSockets
HTTPServerRequestDelegateS handleWebSockets(void delegate(scope WebSocket) @(system) nothrow on_handshake)

Scheduled for deprecation - use a @safe callback instead.

handleWebSockets
HTTPServerRequestDelegateS handleWebSockets(void function(scope WebSocket) @(system) nothrow on_handshake)

Scheduled for deprecation - use a @safe callback instead.

handleWebSockets
HTTPServerRequestDelegateS handleWebSockets(void delegate(scope WebSocket) @(safe) on_handshake)
HTTPServerRequestDelegateS handleWebSockets(void function(scope WebSocket) @(safe) on_handshake)
HTTPServerRequestDelegateS handleWebSockets(void delegate(scope WebSocket) @(system) on_handshake)
HTTPServerRequestDelegateS handleWebSockets(void function(scope WebSocket) @(system) on_handshake)

Scheduled for deprecation - use a nothrow callback instead.

Examples

void handleConn(scope WebSocket sock)
{
	// simple echo server
	while (sock.connected) {
		auto msg = sock.receiveText();
		sock.send(msg);
	}
}

void startServer()
{
	import vibe.http.router;
	auto router = new URLRouter;
	router.get("/ws", handleWebSockets(&handleConn));

	// Start HTTP server using listenHTTP()...
}

Meta

Authors

Jan Krüger

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.