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 the MultiplayerAPI.

Note: When exporting to Android, make sure to enable the INTERNET 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

2048

int

outbound_buffer_size

65535

PackedStringArray

supported_protocols

PackedStringArray()

Methods

Error

create_client ( String url, bool verify_tls=true, X509Certificate tls_certificate=null )

Error

create_server ( int port, String bind_address="*", CryptoKey tls_key=null, X509Certificate tls_certificate=null )

WebSocketPeer

get_peer ( int peer_id ) const

String

get_peer_address ( int id ) const

int

get_peer_port ( int id ) const


Property Descriptions

PackedStringArray handshake_headers = PackedStringArray()

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


float handshake_timeout = 3.0

  • void set_handshake_timeout ( float value )

  • float get_handshake_timeout ( )

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


int inbound_buffer_size = 65535

  • void set_inbound_buffer_size ( int value )

  • int get_inbound_buffer_size ( )

The inbound buffer size for connected peers. See WebSocketPeer.inbound_buffer_size for more details.


int max_queued_packets = 2048

  • void set_max_queued_packets ( int value )

  • int get_max_queued_packets ( )

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


int outbound_buffer_size = 65535

  • void set_outbound_buffer_size ( int value )

  • int get_outbound_buffer_size ( )

The outbound buffer size for connected peers. See WebSocketPeer.outbound_buffer_size for more details.


PackedStringArray supported_protocols = PackedStringArray()

The supported WebSocket sub-protocols. See WebSocketPeer.supported_protocols for more details.


Method Descriptions

Error create_client ( String url, bool verify_tls=true, X509Certificate tls_certificate=null )

Starts a new multiplayer client connecting to the given url. If verify_tls is false certificate validation will be disabled. If specified, the tls_certificate will be used to verify the TLS host.

Note: It is recommended to specify the scheme part of the URL, i.e. the url should start with either ws:// or wss://.


Error create_server ( int port, String bind_address="*", CryptoKey tls_key=null, X509Certificate tls_certificate=null )

Starts a new multiplayer server listening on the given port. You can optionally specify a bind_address, and provide a tls_key and tls_certificate to use TLS.


WebSocketPeer get_peer ( int peer_id ) const

Returns the WebSocketPeer associated to the given peer_id.


String get_peer_address ( int id ) const

Returns the IP address of the given peer.


int get_peer_port ( int id ) const

Returns the remote port of the given peer.