vibe.http.websockets

Implements WebSocket support and fallbacks for older browsers.

Members

Aliases

WebSocketHandshakeDelegate
alias WebSocketHandshakeDelegate = void delegate(scope WebSocket)
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.

Functions

connectWebSocket
WebSocket connectWebSocket(URL url, const(HTTPClientSettings) settings)
void connectWebSocket(URL url, WebSocketHandshakeDelegate del, const(HTTPClientSettings) settings)

Returns a WebSocket client object that is connected to the specified host.

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

Scheduled for deprecation - use a @safe callback instead.

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) on_handshake, HTTPServerRequest req, HTTPServerResponse res)

Scheduled for deprecation - use a @safe callback instead.

handleWebSockets
HTTPServerRequestDelegateS handleWebSockets(void function(scope WebSocket) @(safe) 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) on_handshake)

Scheduled for deprecation - use a @safe callback instead.

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

Scheduled for deprecation - use a @safe 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.