WebsocketConnection

class WebsocketConnection(val soupWebsocketConnectionPointer: <Error class: unknown class><<Error class: unknown class>>)(source)

The WebSocket Protocol

Provides support for the WebSocket protocol.

To connect to a WebSocket server, create a class@Session and call method@Session.websocket_connect_async. To accept WebSocket connections, create a class@Server and add a handler to it with method@Server.add_websocket_handler.

(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 method@WebsocketConnection.send_text and method@WebsocketConnection.send_binary to send data, and the signal@WebsocketConnection::message signal to receive data. (#SoupWebsocketConnection currently only supports asynchronous I/O.)

Skipped during bindings generation

  • parameter data: Array parameter of type guint8 is not supported

Constructors

Link copied to clipboard
constructor(    stream: <Error class: unknown class>,     uri: <Error class: unknown class>,     type: WebsocketConnectionType,     origin: String? = null,     protocol: String? = null,     extensions: <Error class: unknown class>)

Creates a #SoupWebsocketConnection on @stream with the given active @extensions.

constructor(soupWebsocketConnectionPointer: <Error class: unknown class><<Error class: unknown class>>)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The type of connection (client/server).

Link copied to clipboard
val extensions: <Error class: unknown class>

List of class@WebsocketExtension objects that are active in the connection.

Link copied to clipboard
val ioStream: <Error class: unknown class>

The underlying IO stream the WebSocket is communicating over.

Link copied to clipboard
var keepaliveInterval: <Error class: unknown class>

Interval in seconds on when to send a ping message which will serve as a keepalive message.

Link copied to clipboard
var keepalivePongTimeout: <Error class: unknown class>

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.

Link copied to clipboard
var maxIncomingPayloadSize: <Error class: unknown class>

The maximum payload size for incoming packets.

Link copied to clipboard

The client's Origin.

Link copied to clipboard

The chosen protocol, or null if a protocol was not agreed upon.

Link copied to clipboard
val soupWebsocketConnectionPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard

The current state of the WebSocket.

Link copied to clipboard
val uri: <Error class: unknown class>

The URI of the WebSocket.

Functions

Link copied to clipboard
fun close(code: <Error class: unknown class>, data: String? = null)

Close the connection in an orderly fashion.

Link copied to clipboard

Emits the "closed" signal. See onClosed.

Link copied to clipboard

Emits the "closing" signal. See onClosing.

Link copied to clipboard
fun emitError(error: <Error class: unknown class>)

Emits the "error" signal. See onError.

Link copied to clipboard
fun emitMessage(type: <Error class: unknown class>, message: <Error class: unknown class>)

Emits the "message" signal. See onMessage.

Link copied to clipboard
fun emitPong(message: <Error class: unknown class>)

Emits the "pong" signal. See onPong.

Link copied to clipboard
fun getCloseCode(): <Error class: unknown class>

Get the close code received from the WebSocket peer.

Link copied to clipboard

Get the close data received from the WebSocket peer.

Link copied to clipboard
fun onClosed(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: () -> Unit): <Error class: unknown class>

Emitted when the connection has completely closed.

Link copied to clipboard
fun onClosing(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: () -> Unit): <Error class: unknown class>

This signal will be emitted during an orderly close.

Link copied to clipboard
fun onError(    connectFlags: <Error class: unknown class> = ConnectFlags(0u),     handler: (<Error class: unknown class>) -> Unit): <Error class: unknown class>

Emitted when an error occurred on the WebSocket.

Link copied to clipboard
fun onMessage(    connectFlags: <Error class: unknown class> = ConnectFlags(0u),     handler: (<Error class: unknown class>, <Error class: unknown class>) -> Unit): <Error class: unknown class>

Emitted when we receive a message from the peer.

Link copied to clipboard
fun onPong(    connectFlags: <Error class: unknown class> = ConnectFlags(0u),     handler: (<Error class: unknown class>) -> Unit): <Error class: unknown class>

Emitted when we receive a Pong frame (solicited or unsolicited) from the peer.

Link copied to clipboard
fun sendMessage(type: WebsocketDataType, message: <Error class: unknown class>)

Send a message of the given @type to the peer. Note that this method, allows to send text messages containing null characters.

Link copied to clipboard
fun sendText(text: String)

Send a null-terminated text (UTF-8) message to the peer.