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