vibe.d beta banner
get vibe.d

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

Class WebSocket

Represents a single WebSocket connection.

class WebSocket ;
shared static this ()
  runTask(() => connectToWS());

void connectToWS ()
  auto ws_url = URL("wss://");
  auto ws = connectWebSocket(ws_url);
  logInfo("WebSocket connected");

  while (ws.waitForData())
    auto txt = ws.receiveText;
    logInfo("Received: %s", txt);
  logFatal("Connection lost!");


closeCode[get]shortReturns the close code sent by the remote end.
closeReason[get]const(char)[]Returns the close reason sent by the remote end.
connected[get]boolDetermines if the WebSocket connection is still alive and ready for sending.
dataAvailableForRead[get]boolChecks if data is readily available for read.
request[get]const(HTTPServerRequest)The HTTP request that established the web socket connection.


closeActively closes the connection.
receiveReceives a new message using an InputStream.
receiveBinaryReceives a new message and returns its contents as a newly allocated data array.
receiveTextReceives a new message and returns its contents as a newly allocated data array.
sendSends a text message.
sendSends a binary message.
sendSends a message using an output stream.
sendCompatibility overload - will be removed soon.
waitForDataWaits until either a message arrives or until the connection is closed.

Jan Krüger


© 2012-2014 RejectedSoftware e.K.


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