soup.websocket_connection
Module for [WebsocketConnection] class
Types 3
The WebSocket Protocol
Provides support for the WebSocket protocol.
To connect to a WebSocket server, create a class@Session and call [soup.session.Session.websocketConnectAsync]. To accept WebSocket connections, create a class@Server and add a handler to it with [soup.server.Server.addWebsocketHandler].
(Lower-level support is available via func@websocket_client_prepare_handshake and func@websocket_client_verify_handshake, for handling the client side of the WebSocket handshake, and func@websocket_server_process_handshake for handling the server side.)
#SoupWebsocketConnection handles the details of WebSocket communication. You can use [soup.websocket_connection.WebsocketConnection.sendText] and [soup.websocket_connection.WebsocketConnection.sendBinary] to send data, and the signal@WebsocketConnection::message signal to receive data. (#SoupWebsocketConnection currently only supports asynchronous I/O.)
WebsocketConnection self()Returns `this`, for use in `with` statements.WebsocketConnectionGidBuilder builder()Get builder for [soup.websocket_connection.WebsocketConnection] Returns: New builder objectsoup.types.WebsocketConnectionType connectionType() @propertyGet `connectionType` property. Returns: The type of connection (client/server).void * extensions() @propertyGet `extensions` property. Returns: List of `class@WebsocketExtension` objects that are active in the connection.gio.iostream.IOStream ioStream() @propertyGet `ioStream` property. Returns: The underlying IO stream the WebSocket is communicating over.uint keepaliveInterval() @propertyGet `keepaliveInterval` property. Returns: Interval in seconds on when to send a ping message which will serve as a keepalive message.void keepaliveInterval(uint propval) @propertySet `keepaliveInterval` property. Params: propval = Interval in seconds on when to send a ping message which will serve as a keepalive message.ulong maxIncomingPayloadSize() @propertyGet `maxIncomingPayloadSize` property. Returns: The maximum payload size for incoming packets.void maxIncomingPayloadSize(ulong propval) @propertySet `maxIncomingPayloadSize` property. Params: propval = The maximum payload size for incoming packets.string protocol() @propertyGet `protocol` property. Returns: The chosen protocol, or null if a protocol was not agreed upon.soup.types.WebsocketState state() @propertyGet `state` property. Returns: The current state of the WebSocket.void close(ushort code, string data = null)Close the connection in an orderly fashion.ushort getCloseCode()Get the close code received from the WebSocket peer.string getCloseData()Get the close data received from the WebSocket peer.soup.types.WebsocketConnectionType getConnectionType()Get the connection type (client/server) of the connection. Returns: the connection typesoup.websocket_extension.WebsocketExtension[] getExtensions()Get the extensions chosen via negotiation with the peer. Returns: a #GList of #SoupWebsocketExtension objectsgio.iostream.IOStream getIoStream()Get the I/O stream the WebSocket is communicating over. Returns: the WebSocket's I/O stream.uint getKeepaliveInterval()Gets the keepalive interval in seconds or 0 if disabled. Returns: the keepalive interval.ulong getMaxIncomingPayloadSize()Gets the maximum payload size allowed for incoming packets. Returns: the maximum payload size.string getOrigin()Get the origin of the WebSocket. Returns: the originstring getProtocol()Get the protocol chosen via negotiation with the peer. Returns: the chosen protocolsoup.types.WebsocketState getState()Get the current state of the WebSocket. Returns: the stateglib.uri.Uri getUri()Get the URI of the WebSocket.void sendBinary(ubyte[] data = null)Send a binary message to the peer.void sendMessage(soup.types.WebsocketDataType type, glib.bytes.Bytes message)Send a message of the given type to the peer. Note that this method, allows to send text messages containing null characters.void sendText(string text)Send a null-terminated text (UTF-8) message to the peer.void setKeepaliveInterval(uint interval)Sets the interval in seconds on when to send a ping message which will serve as a keepalive message.void setMaxIncomingPayloadSize(ulong maxIncomingPayloadSize)Sets the maximum payload size allowed for incoming packets.gulong connectClosed(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : soup.websocket_connection.WebsocketConnection)))
&& Parameters!T.length < 2)Connect to `Closed` signal.gulong connectClosing(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : soup.websocket_connection.WebsocketConnection)))
&& Parameters!T.length < 2)Connect to `Closing` signal.gulong connectError(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == glib.error.ErrorWrap)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : soup.websocket_connection.WebsocketConnection)))
&& Parameters!T.length < 3)Connect to `Error` signal.gulong connectMessage(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == int)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == glib.bytes.Bytes)))
&& (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : soup.websocket_connection.WebsocketConnection)))
&& Parameters!T.length < 4)Connect to `Message` signal.gulong connectPong(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == glib.bytes.Bytes)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : soup.websocket_connection.WebsocketConnection)))
&& Parameters!T.length < 3)Connect to `Pong` signal.T connectionType(soup.types.WebsocketConnectionType propval)Set `connectionType` property. Params: propval = The type of connection (client/server). Returns: Builder instance for fluent chainingT extensions(void * propval)Set `extensions` property. Params: propval = List of `class@WebsocketExtension` objects that are active in the connection. Returns: Builder instance for fluent chainingT ioStream(gio.iostream.IOStream propval)Set `ioStream` property. Params: propval = The underlying IO stream the WebSocket is communicating over.T keepaliveInterval(uint propval)Set `keepaliveInterval` property. Params: propval = Interval in seconds on when to send a ping message which will serve as a keepalive message.T maxIncomingPayloadSize(ulong propval)Set `maxIncomingPayloadSize` property. Params: propval = The maximum payload size for incoming packets.T origin(string propval)Set `origin` property. Params: propval = The client's Origin. Returns: Builder instance for fluent chainingT protocol(string propval)Set `protocol` property. Params: propval = The chosen protocol, or null if a protocol was not agreed upon. Returns: Builder instance for fluent chainingT uri(glib.uri.Uri propval)Set `uri` property. Params: propval = The URI of the WebSocket.Fluent builder for [soup.websocket_connection.WebsocketConnection]