http.websocket
new_from_uri(uri, protocols) {#http.websocket.new_from_uri}
Creates a new http.websocket object of type "client" from the given URI.
protocols(optional) should be a lua table containing a sequence of protocols to send to the server
new_from_stream(stream, headers) {#http.websocket.new_from_stream}
Attempts to create a new http.websocket object of type "server" from the given request headers and stream.
streamshould be a live HTTP 1 stream of the"server"type.headersshould be headers of a suspected websocket upgrade request from an HTTP 1 client.
This function does not have side effects, and is hence okay to use tentatively.
websocket.close_timeout {#http.websocket.close_timeout}
Amount of time (in seconds) to wait between sending a close frame and actually closing the connection.
Defaults to 3 seconds.
websocket:accept(options, timeout) {#http.websocket:accept}
Completes negotiation with a websocket client.
optionsis a table containing:headers(optional) a headers object to use as a prototype for the response headersprotocols(optional) should be a lua table containing a sequence of protocols to allow from the client
Usually called after a successful new_from_stream
websocket:connect(timeout) {#http.websocket:connect}
Connect to a websocket server.
Usually called after a successful new_from_uri
websocket:receive(timeout) {#http.websocket:receive}
Reads and returns the next data frame plus its opcode. Any ping frames received while reading will be responded to.
The opcode 0x1 will be returned as "text" and 0x2 will be returned as "binary".
websocket:each() {#http.websocket:each}
Iterator over websocket:receive().
websocket:send_frame(frame, timeout) {#http.websocket:send_frame}
Low level function to send a raw frame.
websocket:send(data, opcode, timeout) {#http.websocket:send}
Send the given data as a data frame.
datashould be a stringopcodecan be a numeric opcode,"text"or"binary". Ifnil, defaults to a text frame. Note thisopcodeis the websocket frame opcode, not an application specific opcode. The opcode should be one from the IANA registry.
websocket:send_ping(data, timeout) {#http.websocket:send_ping}
Sends a ping frame.
datais optional
websocket:send_pong(data, timeout) {#http.websocket:send_pong}
Sends a pong frame. Works as a unidirectional keep-alive.
datais optional
websocket:close(code, reason, timeout) {#http.websocket:close}
Closes the websocket connection.
codedefaults to1000reasonis an optional string