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.
Checking the stable version of the documentation...
WebSocketMultiplayerPeer
继承: MultiplayerPeer < PacketPeer < RefCounted < Object
WebSocket 服务器和客户端的基类。
描述
用于 WebSocket 服务器和客户端的基类,可以用作 MultiplayerAPI 的多人对等体。
注意:导出到安卓时,在导出项目或使用一键部署之前,请务必在安卓导出预设中开启 INTERNET
权限。否则,任何类型的网络通信都将被 Android 阻止。
属性
|
||
|
||
|
||
|
||
|
||
|
方法
create_client(url: String, tls_client_options: TLSOptions = null) |
|
create_server(port: int, bind_address: String = "*", tls_server_options: TLSOptions = null) |
|
get_peer_address(id: int) const |
|
get_peer_port(id: int) const |
属性说明
PackedStringArray handshake_headers = PackedStringArray()
🔗
void set_handshake_headers(value: PackedStringArray)
PackedStringArray get_handshake_headers()
握手过程中要使用的额外标头。详见 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
🔗
每个对等体在被丢弃之前可以保持在连接状态的最长时间。
int inbound_buffer_size = 65535
🔗
已连接对等体的入站缓冲区大小。详见 WebSocketPeer.inbound_buffer_size。
int max_queued_packets = 4096
🔗
已连接对等体的最大排队数据包数量。详见 WebSocketPeer.max_queued_packets。
int outbound_buffer_size = 65535
🔗
已连接对等体的出站缓冲区大小。详见 WebSocketPeer.outbound_buffer_size。
PackedStringArray supported_protocols = PackedStringArray()
🔗
void set_supported_protocols(value: PackedStringArray)
PackedStringArray get_supported_protocols()
支持的 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 🔗
返回给定对等体的远程端口。