Soup.WebsocketConnection¶
| Subclasses: | None |
|---|
Methods¶
| Inherited: | GObject.Object (37) |
|---|---|
| Structs: | GObject.ObjectClass (5) |
| class | new (stream, uri, type, origin, protocol) |
| class | new_with_extensions (stream, uri, type, origin, protocol, extensions) |
close (code, data) |
|
get_close_code () |
|
get_close_data () |
|
get_connection_type () |
|
get_extensions () |
|
get_io_stream () |
|
get_keepalive_interval () |
|
get_max_incoming_payload_size () |
|
get_origin () |
|
get_protocol () |
|
get_state () |
|
get_uri () |
|
send_binary (data) |
|
send_message (type, message) |
|
send_text (text) |
|
set_keepalive_interval (interval) |
|
set_max_incoming_payload_size (max_incoming_payload_size) |
Virtual Methods¶
| Inherited: | GObject.Object (7) |
|---|
do_closed () |
|
do_closing () |
|
do_error (error) |
|
do_message (type, message) |
|
do_pong (message) |
Properties¶
| Name | Type | Flags | Short Description |
|---|---|---|---|
connection-type |
Soup.WebsocketConnectionType |
r/w/co | Connection type (client/server) |
extensions |
int |
r/w/co | The list of active extensions |
io-stream |
Gio.IOStream |
r/w/co | Underlying I/O stream |
keepalive-interval |
int |
r/w/c | Keepalive interval |
max-incoming-payload-size |
int |
r/w/c | Max incoming payload size |
origin |
str |
r/w/co | The WebSocket origin |
protocol |
str |
r/w/co | The chosen WebSocket protocol |
state |
Soup.WebsocketState |
r | State |
uri |
Soup.URI |
r/w/co | The WebSocket URI |
Signals¶
| Inherited: | GObject.Object (1) |
|---|
| Name | Short Description |
|---|---|
closed |
Emitted when the connection has completely closed, either due to an orderly close from the peer, one initiated via Soup.WebsocketConnection.close() or a fatal error condition that caused a close. |
closing |
This signal will be emitted during an orderly close. |
error |
Emitted when an error occurred on the WebSocket. |
message |
Emitted when we receive a message from the peer. |
pong |
Emitted when we receive a Pong frame (solicited or unsolicited) from the peer. |
Class Details¶
-
class
Soup.WebsocketConnection(**kwargs)¶ Bases: GObject.ObjectAbstract: No Structure: Soup.WebsocketConnectionClassA class representing a WebSocket connection.
New in version 2.50.
-
classmethod
new(stream, uri, type, origin, protocol)¶ Parameters: - stream (
Gio.IOStream) – aGio.IOStreamconnected to the WebSocket server - uri (
Soup.URI) – the URI of the connection - type (
Soup.WebsocketConnectionType) – the type of connection (client/side) - origin (
strorNone) – the Origin of the client - protocol (
strorNone) – the subprotocol in use
Returns: a new
Soup.WebsocketConnectionReturn type: Creates a
Soup.WebsocketConnectionon stream. This should be called after completing the handshake to begin using the WebSocket protocol.New in version 2.50.
- stream (
-
classmethod
new_with_extensions(stream, uri, type, origin, protocol, extensions)¶ Parameters: - stream (
Gio.IOStream) – aGio.IOStreamconnected to the WebSocket server - uri (
Soup.URI) – the URI of the connection - type (
Soup.WebsocketConnectionType) – the type of connection (client/side) - origin (
strorNone) – the Origin of the client - protocol (
strorNone) – the subprotocol in use - extensions ([
Soup.WebsocketExtension]) – aGLib.ListofSoup.WebsocketExtensionobjects
Returns: a new
Soup.WebsocketConnectionReturn type: Creates a
Soup.WebsocketConnectionon stream with the given active extensions. This should be called after completing the handshake to begin using the WebSocket protocol.New in version 2.68.
- stream (
-
close(code, data)¶ Parameters: Close the connection in an orderly fashion.
Note that until the
Soup.WebsocketConnection::closedsignal 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
Soup.WebsocketCloseCode.NO_STATUSa close message with no body (without code and data) is sent. Note that the data must be UTF-8 valid.New in version 2.50.
-
get_close_code()¶ Returns: the close code or zero. Return type: intGet the close code received from the WebSocket peer.
This only becomes valid once the WebSocket is in the
Soup.WebsocketState.CLOSEDstate. The value will often be in theSoup.WebsocketCloseCodeenumeration, but may also be an application defined close code.New in version 2.50.
-
get_close_data()¶ Returns: the close data or NoneReturn type: strGet the close data received from the WebSocket peer.
This only becomes valid once the WebSocket is in the
Soup.WebsocketState.CLOSEDstate. The data may be freed once the main loop is run, so copy it if you need to keep it around.New in version 2.50.
-
get_connection_type()¶ Returns: the connection type Return type: Soup.WebsocketConnectionTypeGet the connection type (client/server) of the connection.
New in version 2.50.
-
get_extensions()¶ Returns: a GLib.ListofSoup.WebsocketExtensionobjectsReturn type: [ Soup.WebsocketExtension]Get the extensions chosen via negotiation with the peer.
New in version 2.68.
-
get_io_stream()¶ Returns: the WebSocket’s I/O stream. Return type: Gio.IOStreamGet the I/O stream the WebSocket is communicating over.
New in version 2.50.
-
get_keepalive_interval()¶ Returns: the keepalive interval. Return type: intGets the keepalive interval in seconds or 0 if disabled.
New in version 2.58.
-
get_max_incoming_payload_size()¶ Returns: the maximum payload size. Return type: intGets the maximum payload size allowed for incoming packets.
New in version 2.56.
-
get_origin()¶ Returns: the origin, or NoneReturn type: strorNoneGet the origin of the WebSocket.
New in version 2.50.
-
get_protocol()¶ Returns: the chosen protocol, or NoneReturn type: strorNoneGet the protocol chosen via negotiation with the peer.
New in version 2.50.
-
get_state()¶ Returns: the state Return type: Soup.WebsocketStateGet the current state of the WebSocket.
New in version 2.50.
-
get_uri()¶ Returns: the URI Return type: Soup.URIGet the URI of the WebSocket.
For servers this represents the address of the WebSocket, and for clients it is the address connected to.
New in version 2.50.
-
send_binary(data)¶ Parameters: data ( bytesorNone) – the message contentsSend a binary message to the peer. If length is 0, data may be
None.The message is queued to be sent and will be sent when the main loop is run.
New in version 2.50.
-
send_message(type, message)¶ Parameters: - type (
Soup.WebsocketDataType) – the type of message contents - message (
GLib.Bytes) – the message data asGLib.Bytes
Send a message of the given type to the peer. Note that this method, allows to send text messages containing
Nonecharacters.The message is queued to be sent and will be sent when the main loop is run.
New in version 2.68.
- type (
-
send_text(text)¶ Parameters: text ( str) – the message contentsSend a
None-terminated text (UTF-8) message to the peer. If you need to send text messages containingNonecharacters useSoup.WebsocketConnection.send_message() instead.The message is queued to be sent and will be sent when the main loop is run.
New in version 2.50.
-
set_keepalive_interval(interval)¶ Parameters: interval ( int) – the interval to send a ping message or 0 to disable itSets 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.
New in version 2.58.
-
set_max_incoming_payload_size(max_incoming_payload_size)¶ Parameters: max_incoming_payload_size ( int) – the maximum payload sizeSets the maximum payload size allowed for incoming packets. It does not limit the outgoing packet size.
New in version 2.56.
-
do_closed() virtual¶
-
do_closing() virtual¶
-
do_error(error) virtual¶ Parameters: error ( GLib.Error) –
-
do_message(type, message) virtual¶ Parameters: - type (
Soup.WebsocketDataType) – - message (
GLib.Bytes) –
- type (
-
do_pong(message) virtual¶ Parameters: message ( GLib.Bytes) –
-
classmethod
Signal Details¶
-
Soup.WebsocketConnection.signals.closed(websocket_connection)¶ Signal Name: closedFlags: RUN_FIRSTParameters: websocket_connection ( Soup.WebsocketConnection) – The object which received the signalEmitted when the connection has completely closed, either due to an orderly close from the peer, one initiated via
Soup.WebsocketConnection.close() or a fatal error condition that caused a close.This signal will be emitted once.
New in version 2.50.
-
Soup.WebsocketConnection.signals.closing(websocket_connection)¶ Signal Name: closingFlags: RUN_LASTParameters: websocket_connection ( Soup.WebsocketConnection) – The object which received the signalThis signal will be emitted during an orderly close.
New in version 2.50.
-
Soup.WebsocketConnection.signals.error(websocket_connection, error)¶ Signal Name: errorFlags: Parameters: - websocket_connection (
Soup.WebsocketConnection) – The object which received the signal - error (
GLib.Error) – the error that occured
Emitted when an error occurred on the WebSocket. This may be fired multiple times. Fatal errors will be followed by the
Soup.WebsocketConnection::closedsignal being emitted.New in version 2.50.
- websocket_connection (
-
Soup.WebsocketConnection.signals.message(websocket_connection, type, message)¶ Signal Name: messageFlags: Parameters: - websocket_connection (
Soup.WebsocketConnection) – The object which received the signal - type (
int) – the type of message contents - message (
GLib.Bytes) – the message data
Emitted when we receive a message from the peer.
As a convenience, the message data will always be NUL-terminated, but the NUL byte will not be included in the length count.
New in version 2.50.
- websocket_connection (
-
Soup.WebsocketConnection.signals.pong(websocket_connection, message)¶ Signal Name: pongFlags: Parameters: - websocket_connection (
Soup.WebsocketConnection) – The object which received the signal - message (
GLib.Bytes) – the application data (if any)
Emitted when we receive a Pong frame (solicited or unsolicited) from the peer.
As a convenience, the message data will always be NUL-terminated, but the NUL byte will not be included in the length count.
New in version 2.60.
- websocket_connection (
Property Details¶
-
Soup.WebsocketConnection.props.connection_type¶ Name: connection-typeType: Soup.WebsocketConnectionTypeDefault Value: Soup.WebsocketConnectionType.UNKNOWNFlags: READABLE,WRITABLE,CONSTRUCT_ONLYThe type of connection (client/server).
New in version 2.50.
-
Soup.WebsocketConnection.props.extensions¶ Name: extensionsType: intDefault Value: NoneFlags: READABLE,WRITABLE,CONSTRUCT_ONLYList of
Soup.WebsocketExtensionobjects that are active in the connection.New in version 2.68.
-
Soup.WebsocketConnection.props.io_stream¶ Name: io-streamType: Gio.IOStreamDefault Value: NoneFlags: READABLE,WRITABLE,CONSTRUCT_ONLYThe underlying IO stream the WebSocket is communicating over.
The input and output streams must be pollable streams.
New in version 2.50.
-
Soup.WebsocketConnection.props.keepalive_interval¶ Name: keepalive-intervalType: intDefault Value: 0Flags: READABLE,WRITABLE,CONSTRUCTInterval 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.
New in version 2.58.
-
Soup.WebsocketConnection.props.max_incoming_payload_size¶ Name: max-incoming-payload-sizeType: intDefault Value: 131072Flags: READABLE,WRITABLE,CONSTRUCTThe maximum payload size for incoming packets the protocol expects or 0 to not limit it.
New in version 2.56.
-
Soup.WebsocketConnection.props.origin¶ Name: originType: strDefault Value: NoneFlags: READABLE,WRITABLE,CONSTRUCT_ONLYThe client’s Origin.
New in version 2.50.
-
Soup.WebsocketConnection.props.protocol¶ Name: protocolType: strDefault Value: NoneFlags: READABLE,WRITABLE,CONSTRUCT_ONLYThe chosen protocol, or
Noneif a protocol was not agreed upon.New in version 2.50.
-
Soup.WebsocketConnection.props.state¶ Name: stateType: Soup.WebsocketStateDefault Value: Soup.WebsocketState.OPENFlags: READABLEThe current state of the WebSocket.
New in version 2.50.