Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

WebSocketMultiplayerPeer

繼承: MultiplayerPeer < PacketPeer < RefCounted < Object

WebSocket 伺服器和使用者端的基底類別。

說明

用於 WebSocket 伺服器和使用者端的基底類別,可以用作 MultiplayerAPI 的多人對等體。

注意:匯出到安卓時,在匯出專案或使用一鍵部署之前,請務必在安卓匯出預設中開啟 INTERNET 許可權。否則,任何型別的網路通信都將被 Android 阻止。

屬性

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()

方法

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


屬性說明

PackedStringArray handshake_headers = PackedStringArray() 🔗

握手過程中要使用的額外標頭。詳見 WebSocketPeer.handshake_headers

Note: The returned array is copied and any changes to it will not update the original property value. See PackedStringArray for more details.


float handshake_timeout = 3.0 🔗

  • void set_handshake_timeout(value: float)

  • float get_handshake_timeout()

每個對等體在被丟棄之前可以保持在連接狀態的最長時間。


int inbound_buffer_size = 65535 🔗

  • void set_inbound_buffer_size(value: int)

  • int get_inbound_buffer_size()

已連接對等體的入站緩衝區大小。詳見 WebSocketPeer.inbound_buffer_size


int max_queued_packets = 4096 🔗

  • void set_max_queued_packets(value: int)

  • int get_max_queued_packets()

已連接對等體的最大排隊封包數量。詳見 WebSocketPeer.max_queued_packets


int outbound_buffer_size = 65535 🔗

  • void set_outbound_buffer_size(value: int)

  • int get_outbound_buffer_size()

已連接對等體的出站緩衝區大小。詳見 WebSocketPeer.outbound_buffer_size


PackedStringArray supported_protocols = PackedStringArray() 🔗

支援的 WebSocket 子協定。詳情見 WebSocketPeer.supported_protocols

Note: The returned array is copied and any changes to it will not update the original property value. See PackedStringArray for more details.


方法說明

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

啟動新的多人使用者端,連接至給定的 url。使用 wss:// 協議連接時會校驗主機名稱和 TLS 憑證。傳入 tls_client_options 可以自訂信任的憑證授權,也可以禁用通用名的驗證。見 TLSOptions.client()TLSOptions.client_unsafe()

注意:推薦指定 URL 的方案部分,即 url 應該以 ws://wss:// 開頭。


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

啟動新的多人伺服器,監聽給定的 port。可以指定 bind_address,也可以提供有效的 tls_server_options 來使用 TLS。見 TLSOptions.server()


WebSocketPeer get_peer(peer_id: int) const 🔗

返回與給定 peer_id 關聯的 WebSocketPeer


String get_peer_address(id: int) const 🔗

返回給定對等體的 IP 位址。


int get_peer_port(id: int) const 🔗

返回給定對等體的遠端埠。