It derives from <GObject>.
The WebSocket Protocol
Provides support for the WebSocket protocol.
To connect to a WebSocket server, create a Session and call
Session.websocket_connect_async. To accept WebSocket
connections, create a Server and add a handler to it with
Server.add_websocket_handler.
(Lower-level support is available via
websocket_client_prepare_handshake and
websocket_client_verify_handshake, for handling the client side
of the WebSocket handshake, and
websocket_server_process_handshake for handling the server side.)
WebsocketConnection handles the details of WebSocket
communication. You can use WebsocketConnection.send_text and
WebsocketConnection.send_binary to send data, and the
"message" signal to receive data. (WebsocketConnection
currently only supports asynchronous I/O.)
The type of connection (client/server).
Its value is a
<SoupWebsocketConnectionType> (or,
to set it, one of its symbols).
It can only be set when the object is made, with
#:connection-type.
List of WebsocketExtension objects that are active in the
connection.
Its value is a foreign pointer (or, to set it, a bytevector).
It can only be set when the object is made, with #:extensions.
The underlying IO stream the WebSocket is communicating over.
The input and output streams must be pollable streams.
Its value is a <GIOStream>, or #f.
It can only be set when the object is made, with #:io-stream.
Interval in seconds on when to send a ping message which will serve as a keepalive message.
If set to 0 the keepalive message is disabled.
Its value is an unsigned 32-bit integer.
Set it with (set! (websocket-connection:keepalive-interval self)
value).
Timeout in seconds for when the absence of a pong from a keepalive ping is assumed to be caused by a faulty connection. The WebSocket will be transitioned to a closed state when this happens.
If set to 0 then the absence of pongs from keepalive pings is ignored.
Its value is an unsigned 32-bit integer.
Set it with (set! (websocket-connection:keepalive-pong-timeout
self) value).
The maximum payload size for incoming packets.
The protocol expects or 0 to not limit it.
Its value is an unsigned 64-bit integer.
Set it with (set! (websocket-connection:max-incoming-payload-size
self) value).
The client’s Origin.
Its value is a string, or #f.
It can only be set when the object is made, with #:origin.
The chosen protocol, or #f if a protocol was not agreed upon.
Its value is a string, or #f.
It can only be set when the object is made, with #:protocol.
The current state of the WebSocket.
Its value is a <SoupWebsocketState>.
It is read only.
The URI of the WebSocket.
For servers this represents the address of the WebSocket, and for clients it is the address connected to.
Its value is a <GUri>, or #f.
It can only be set when the object is made, with #:uri.
Close the connection in an orderly fashion.
Note that until the "closed" signal fires, the connection is not
yet completely closed. The close message is not even sent until the
main loop runs.
The code and data are sent to the peer along with the close
request. If code is no-status a
close message with no body (without code and data) is sent. Note that
the data must be UTF-8 valid.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Passed: an unsigned 16-bit integer.
close code
Passed, or left out: a string, or #f.
close data
Get the close code received from the WebSocket peer.
This only becomes valid once the WebSocket is in the
closed state. The value will often be in
the WebsocketCloseCode enumeration, but may also be an
application defined close code.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Returned: an unsigned 16-bit integer.
the close code or zero.
Get the close data received from the WebSocket peer.
This only becomes valid once the WebSocket is in the
closed state. The data may be freed once
the main loop is run, so copy it if you need to keep it around.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Returned: a string.
the close data or #f
Get the connection type (client/server) of the connection.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Returned: a
<SoupWebsocketConnectionType>.
the connection type
Get the extensions chosen via negotiation with the peer.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Returned: a list, each a
<SoupWebsocketExtension>.
a GList of
<SoupWebsocketExtension> objects
Get the I/O stream the WebSocket is communicating over.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Returned: a <GIOStream>.
the WebSocket’s I/O stream.
Gets the keepalive interval in seconds or 0 if disabled.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Returned: an unsigned 32-bit integer.
the keepalive interval.
Gets the keepalive pong timeout in seconds or 0 if disabled.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Returned: an unsigned 32-bit integer.
the keepalive pong timeout.
Gets the maximum payload size allowed for incoming packets.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Returned: an unsigned 64-bit integer.
the maximum payload size.
Get the origin of the WebSocket.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Returned: a string, or #f.
the origin
Get the protocol chosen via negotiation with the peer.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Returned: a string, or #f.
the chosen protocol
Get the current state of the WebSocket.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Returned: a <SoupWebsocketState>.
the state
Get the URI of the WebSocket.
For servers this represents the address of the WebSocket, and for clients it is the address connected to.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Returned: a <GUri>.
the URI
Creates a WebsocketConnection on stream with the given
active extensions.
This should be called after completing the handshake to begin using the WebSocket protocol.
Passed: a <GIOStream>.
a <GIOStream> connected to the WebSocket
server
Passed: a <GUri>.
the URI of the connection
Passed: a
<SoupWebsocketConnectionType>, or
one of its symbols.
the type of connection (client/side)
Passed: a string, or #f.
the Origin of the client
Passed: a string, or #f.
the subprotocol in use
Passed: a list, each a
<SoupWebsocketExtension>.
a GList of
<SoupWebsocketExtension> objects
Returned: a <SoupWebsocketConnection>.
Send a binary message to the peer.
If length is 0, data may be #f.
The message is queued to be sent and will be sent when the main loop is run.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Passed: a bytevector, or a list or vector, each an unsigned 8-bit
integer, or #f.
the message contents
Not passed: guile-gi gives the length of data.
the length of data
Send a message of the given type to the peer. Note that this
method, allows to send text messages containing #f characters.
The message is queued to be sent and will be sent when the main loop is run.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Passed: a <SoupWebsocketDataType>, or
one of its symbols.
the type of message contents
Passed: a <GBytes>.
the message data as <GBytes>
Send a #f-terminated text (UTF-8) message to the peer.
If you need to send text messages containing #f characters use
WebsocketConnection.send_message instead.
The message is queued to be sent and will be sent when the main loop is run.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Passed: a string.
the message contents
Sets the interval in seconds on when to send a ping message which will serve as a keepalive message.
If set to 0 the keepalive message is disabled.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Passed: an unsigned 32-bit integer.
the interval to send a ping message or 0 to disable it
Set the timeout in seconds for when the absence of a pong from a keepalive ping is assumed to be caused by a faulty connection.
If set to 0 then the absence of pongs from keepalive pings is ignored.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Passed: an unsigned 32-bit integer.
the timeout in seconds
Sets the maximum payload size allowed for incoming packets.
It does not limit the outgoing packet size.
Passed: a <SoupWebsocketConnection>.
the WebSocket
Passed: an unsigned 64-bit integer.
the maximum payload size
Connect a handler with (connect object websocket-connection:closed
handler). It is called as (handler self).
Emitted when the connection has completely closed.
This happens either due to an orderly close from the peer, one initiated
via WebsocketConnection.close or a fatal error condition that
caused a close.
This signal will be emitted once.
Passed: a <SoupWebsocketConnection>.
Connect a handler with (connect object
websocket-connection:closing handler). It is called as (handler
self).
This signal will be emitted during an orderly close.
Passed: a <SoupWebsocketConnection>.
Connect a handler with (connect object websocket-connection:error
handler). It is called as (handler self error).
Emitted when an error occurred on the WebSocket.
This may be fired multiple times. Fatal errors will be followed by the
"closed" signal being emitted.
Passed: a <SoupWebsocketConnection>.
Passed: a <GError>.
the error that occured
Connect a handler with (connect object
websocket-connection:message handler). It is called as (handler
self type message).
Emitted when we receive a message from the peer.
As a convenience, the message data will always be
#f-terminated, but the NUL byte will not be included in the
length count.
Passed: a <SoupWebsocketConnection>.
Passed: a 32-bit integer.
the type of message contents
Passed: a <GBytes>.
the message data
Connect a handler with (connect object websocket-connection:pong
handler). It is called as (handler self message).
Emitted when we receive a Pong frame (solicited or unsolicited) from the peer.
As a convenience, the message data will always be
#f-terminated, but the NUL byte will not be included in the
length count.
Passed: a <SoupWebsocketConnection>.
Passed: a <GBytes>.
the application data (if any)