vibe.d beta banner
get vibe.d
0.10.1

Asynchronous I/O that doesn’t get in your way, written in D

Module vibe.http.websockets

Implements WebSocket support and fallbacks for older browsers.

Standards

RFC6455

Example

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()...
}

Functions

NameDescription
closeReasonString(reason)
connectWebSocket(url, settings) Establishes a WebSocket connection at the specified endpoint.
connectWebSocket(url, del, settings) Scheduled for deprecation - use a @safe callback instead.
connectWebSocket(url, del, settings) Scheduled for deprecation - use a nothrow callback instead.
connectWebSocketEx(url, request_modifier, settings) Establishes a WebSocket connection at the specified endpoint.
handleWebSocket(on_handshake, req, res) Establishes a web socket conection and passes it to the on_handshake delegate.
handleWebSocket(on_handshake, req, res) Scheduled for deprecation - use a @safe callback instead.
handleWebSocket(on_handshake, req, res) Scheduled for deprecation - use a nothrow callback instead.
handleWebSockets(on_handshake) Returns a HTTP request handler that establishes web socket conections.
handleWebSockets(on_handshake) Scheduled for deprecation - use a @safe callback instead.
handleWebSockets(on_handshake) Scheduled for deprecation - use a nothrow callback instead.

Classes

NameDescription
IncomingWebSocketMessage Represents a single incoming WebSocket message as an InputStream.
OutgoingWebSocketMessage Represents a single outgoing WebSocket message as an OutputStream.
WebSocket Represents a single WebSocket connection.
WebSocketException Exception thrown by vibe.http.websockets.

Enums

NameDescription
FrameOpcode The Opcode is 4 bits, as defined in Section 5.2
WebSocketCloseReason Provides the reason that a websocket connection has closed.

Aliases

NameTypeDescription
WebSocketHandshakeDelegate nothrow @safe void delegate(scope WebSocket)
Authors

Jan Krüger

Copyright

© 2012-2014 Sönke Ludwig

License

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