WebSocketCloseReason

Provides the reason that a websocket connection has closed.

Further documentation for the WebSocket and it's codes can be found from: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent

void echoSocket(scope WebSocket sock)
{
  import std.datetime : seconds;

  while(sock.waitForData(3.seconds))
  {
    string msg = sock.receiveText;
    logInfo("Got a message: %s", msg);
    sock.send(msg);
  }

  if(sock.connected)
    sock.close(WebSocketCloseReason.policyViolation, "timeout");
}

Values

ValueMeaning
none0
normalClosure1000
goingAway1001
protocolError1002
unsupportedData1003
noStatusReceived1005
abnormalClosure1006
invalidFramePayloadData1007
policyViolation1008
messageTooBig1009
internalError1011
serviceRestart1012
tryAgainLater1013
badGateway1014
tlsHandshake1015

Meta