WebSocketMultiplayerPeer
Inherits: MultiplayerPeer < PacketPeer < RefCounted < Object
Description
Section titled “Description”Base class for WebSocket server and client.
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 remote deploy. Otherwise, network communication of any kind will be blocked by Android.
Properties
Section titled “Properties”| Type | Name | Default |
|---|---|---|
| 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
Section titled “Methods”| Returns | Method |
|---|---|
| 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
Section titled “Property descriptions”handshake_headers
PackedStringArray handshake_headers = PackedStringArray()
The extra headers to use during handshake. See WebSocketPeer.handshake_headers for more details.
handshake_timeout
float handshake_timeout = 3.0
The maximum time each peer can stay in a connecting state before being dropped.
inbound_buffer_size
int inbound_buffer_size = 65535
The inbound buffer size for connected peers. See WebSocketPeer.inbound_buffer_size for more details.
max_queued_packets
int max_queued_packets = 4096
The maximum number of queued packets for connected peers. See WebSocketPeer.max_queued_packets for more details.
outbound_buffer_size
int outbound_buffer_size = 65535
The outbound buffer size for connected peers. See WebSocketPeer.outbound_buffer_size for more details.
supported_protocols
PackedStringArray supported_protocols = PackedStringArray()
The supported WebSocket sub-protocols. See WebSocketPeer.supported_protocols for more details.
Method descriptions
Section titled “Method descriptions”create_client
Error create_client(url: String, tls_client_options: TLSOptions = null)
Starts a new multiplayer client connecting to the given url. TLS certificates will be verified against the hostname when connecting using the wss:// protocol. You can pass the optional tls_client_options parameter to customize the trusted certification authorities, or disable the common name verification. See TLSOptions.client() and TLSOptions.client_unsafe().
Note: It is recommended to specify the scheme part of the URL, i.e. the url should start with either ws:// or wss://.
create_server
Error create_server(port: int, bind_address: String = "*", tls_server_options: TLSOptions = null)
Starts a new multiplayer server listening on the given port. You can optionally specify a bind_address, and provide valid tls_server_options to use TLS. See TLSOptions.server().
get_peer
WebSocketPeer get_peer(peer_id: int) const
Returns the WebSocketPeer associated to the given peer_id.
get_peer_address
String get_peer_address(id: int) const
Returns the IP address of the given peer.
get_peer_port
int get_peer_port(id: int) const
Returns the remote port of the given peer.
