WebSocketMultiplayerPeer

Inherits:MultiplayerPeer<PacketPeer<RefCounted<Object

Base class for WebSocket server and client.

Description

Base class for WebSocket server and client, allowing them to be used as multiplayer peer for theMultiplayerAPI.

Note: When exporting to Android, make sure to enable theINTERNET permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android.

Properties

PackedStringArray

handshake_headers

PackedStringArray()

float

handshake_timeout

3.0

int

inbound_buffer_size

65535

int

max_queued_packets

4096

int

outbound_buffer_size

65535

PackedStringArray

supported_protocols

PackedStringArray()

Methods

Error

create_client(url:String, tls_client_options:TLSOptions = null)

Error

create_server(port:int, bind_address:String = "*", tls_server_options:TLSOptions = null)

WebSocketPeer

get_peer(peer_id:int)const

String

get_peer_address(id:int)const

int

get_peer_port(id:int)const


Property Descriptions

PackedStringArrayhandshake_headers =PackedStringArray()🔗

The extra headers to use during handshake. SeeWebSocketPeer.handshake_headers for more details.

Note: The returned array iscopied and any changes to it will not update the original property value. SeePackedStringArray for more details.


floathandshake_timeout =3.0🔗

The maximum time each peer can stay in a connecting state before being dropped.


intinbound_buffer_size =65535🔗

The inbound buffer size for connected peers. SeeWebSocketPeer.inbound_buffer_size for more details.


intmax_queued_packets =4096🔗

The maximum number of queued packets for connected peers. SeeWebSocketPeer.max_queued_packets for more details.


intoutbound_buffer_size =65535🔗

The outbound buffer size for connected peers. SeeWebSocketPeer.outbound_buffer_size for more details.


PackedStringArraysupported_protocols =PackedStringArray()🔗

The supported WebSocket sub-protocols. SeeWebSocketPeer.supported_protocols for more details.

Note: The returned array iscopied and any changes to it will not update the original property value. SeePackedStringArray for more details.


Method Descriptions

Errorcreate_client(url:String, tls_client_options:TLSOptions = null)🔗

Starts a new multiplayer client connecting to the givenurl. TLS certificates will be verified against the hostname when connecting using thewss:// protocol. You can pass the optionaltls_client_options parameter to customize the trusted certification authorities, or disable the common name verification. SeeTLSOptions.client() andTLSOptions.client_unsafe().

Note: It is recommended to specify the scheme part of the URL, i.e. theurl should start with eitherws:// orwss://.


Errorcreate_server(port:int, bind_address:String = "*", tls_server_options:TLSOptions = null)🔗

Starts a new multiplayer server listening on the givenport. You can optionally specify abind_address, and provide validtls_server_options to use TLS. SeeTLSOptions.server().


WebSocketPeerget_peer(peer_id:int)const🔗

Returns theWebSocketPeer associated to the givenpeer_id.


Stringget_peer_address(id:int)const🔗

Returns the IP address of the given peer.


intget_peer_port(id:int)const🔗

Returns the remote port of the given peer.


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.