Table of Contents

Class WebSocketMultiplayerPeer

Namespace
Godot
Assembly
GodotSharp.dll

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.

public class WebSocketMultiplayerPeer : MultiplayerPeer, IDisposable
Inheritance
WebSocketMultiplayerPeer
Implements
Inherited Members

Constructors

WebSocketMultiplayerPeer()

public WebSocketMultiplayerPeer()

Properties

HandshakeHeaders

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

public string[] HandshakeHeaders { get; set; }

Property Value

string[]

HandshakeTimeout

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

public float HandshakeTimeout { get; set; }

Property Value

float

InboundBufferSize

The inbound buffer size for connected peers. See InboundBufferSize for more details.

public int InboundBufferSize { get; set; }

Property Value

int

MaxQueuedPackets

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

public int MaxQueuedPackets { get; set; }

Property Value

int

OutboundBufferSize

The outbound buffer size for connected peers. See OutboundBufferSize for more details.

public int OutboundBufferSize { get; set; }

Property Value

int

SupportedProtocols

The supported WebSocket sub-protocols. See SupportedProtocols for more details.

public string[] SupportedProtocols { get; set; }

Property Value

string[]

Methods

CreateClient(string, TlsOptions)

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 tlsClientOptions parameter to customize the trusted certification authorities, or disable the common name verification. See Client(X509Certificate, string) and ClientUnsafe(X509Certificate).

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

public Error CreateClient(string url, TlsOptions tlsClientOptions = null)

Parameters

url string
tlsClientOptions TlsOptions

Returns

Error

CreateServer(int, string, TlsOptions)

Starts a new multiplayer server listening on the given port. You can optionally specify a bindAddress, and provide valid tlsServerOptions to use TLS. See Server(CryptoKey, X509Certificate).

public Error CreateServer(int port, string bindAddress = "*", TlsOptions tlsServerOptions = null)

Parameters

port int
bindAddress string
tlsServerOptions TlsOptions

Returns

Error

GetPeer(int)

Returns the WebSocketPeer associated to the given peerId.

public WebSocketPeer GetPeer(int peerId)

Parameters

peerId int

Returns

WebSocketPeer

GetPeerAddress(int)

Returns the IP address of the given peer.

public string GetPeerAddress(int id)

Parameters

id int

Returns

string

GetPeerPort(int)

Returns the remote port of the given peer.

public int GetPeerPort(int id)

Parameters

id int

Returns

int

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool