vibe.d beta banner
get vibe.d
0.10.1

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

Enum WebSocketCloseReason

Provides the reason that a websocket connection has closed.

enum WebSocketCloseReason : short { ... }

Further documentation for the WebSocket and it's codes can be found from:

Enum members

NameDescription
abnormalClosure
badGateway
goingAway
internalError
invalidFramePayloadData
messageTooBig
none
normalClosure
noStatusReceived
policyViolation
protocolError
serviceRestart
tlsHandshake
tryAgainLater
unsupportedData

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");
}
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.