← index

WebSocket

inherits Object · defined at net/websocket.qn:21

Class methods

acceptFor:String

The RFC 6455 accept token for a key — what an upgrade response must echo. Class-side so a Quoin SERVER can compute it too.

net/websocket.qn:62

connect:

Open a WebSocket to a ws:// or wss:// URL: connect (TLS for wss), send the HTTP/1.1 upgrade with a random Sec-WebSocket-Key, and VERIFY the 101 response's Sec-WebSocket-Accept (base64(sha1(key + GUID))) — a wrong status or accept throws an IoError.

net/websocket.qn:27

parseWsUrl:

Internal: 'ws(s)://host[:port]/path?query' -> #( secure host port path ).

net/websocket.qn:67

Instance methods

close

Close with code 1000 (normal). See close:reason:.

net/websocket.qn:166

close:Integer reason:String

Run the close handshake: send a close frame, then drain incoming frames until the far side's close reply (data still in flight is discarded). Idempotent; a connection torn mid-handshake still ends closed. Returns nil.

net/websocket.qn:171

closeCode

The close code the far side sent (1005 when its close frame carried none), or nil while open.

net/websocket.qn:98

closeReason

The close reason text (possibly ''), or nil while open.

net/websocket.qn:101

closed?

Whether the connection has closed (cleanly or by error).

net/websocket.qn:94

eachMessage:

Loop receive into the block until the connection closes; answers self.

net/websocket.qn:157

handleClose:

A close frame arrived: record code/reason, echo the close unless we already sent ours, and tear down. Answers nil (receive's close answer).

net/websocket.qn:245

init

Internal.

net/websocket.qn:85

ping

Send a ping (the far side must pong; incoming pings are answered automatically inside receive). Answers self.

net/websocket.qn:117

ping:

A ping carrying a payload (String or Bytes, <= 125 bytes).

net/websocket.qn:120

readFrame

One frame off the wire: #( fin opcode payload ). Server frames must be unmasked; reserved bits mean an extension we never negotiated.

net/websocket.qn:191

receive

The next message: a String for a text frame, Bytes for binary — or nil once the connection closes cleanly. Fragmented messages are reassembled; pings are ponged and pongs ignored, invisibly. Parks the task while waiting. A connection torn without a close frame throws an IoError.

net/websocket.qn:130

s

net/websocket.qn:265

sendBytes:Bytes

Send a binary message. Answers self.

net/websocket.qn:110

sendFrame: payload:Bytes

Mask and send one frame (fin always set — we never fragment sends).

net/websocket.qn:216

sendText:String

Send a text message (one frame, masked). Answers self.

net/websocket.qn:104

url

The URL this socket connected to.

net/websocket.qn:91