class WebSocketServer
package godot
extends WebSocketMultiplayerPeer › NetworkedMultiplayerPeer › PacketPeer › Reference › Object
This class implements a WebSocket server that can also support the high-level multiplayer API.
After starting the server (godot.WebSocketServer.listen
), you will need to godot.NetworkedMultiplayerPeer.poll
it at regular intervals (e.g. inside godot.Node._Process
). When clients connect, disconnect, or send data, you will receive the appropriate signal.
Note: Not available in HTML5 exports.
Constructor
Variables
bindIp:String
When not set to *
will restrict incoming connections to the specified IP address. Setting bind_ip
to 127.0.0.1
will cause the server to listen only to the local host.
caChain:X509Certificate
When using SSL (see godot.WebSocketServer.privateKey
and godot.WebSocketServer.sslCertificate
), you can set this to a valid godot.X509Certificate
to be provided as additional CA chain information during the SSL handshake.
handshakeTimeout:Single
The time in seconds before a pending client (i.e. a client that has not yet finished the HTTP handshake) is considered stale and forcefully disconnected.
read onlyonClientCloseRequest:Signal<(id:Int, code:Int, reason:String) ‑> Void>
client_close_request
signal.
read onlyonClientDisconnected:Signal<(id:Int, wasCleanClose:Bool) ‑> Void>
client_disconnected
signal.
privateKey:CryptoKey
When set to a valid godot.CryptoKey
(along with godot.WebSocketServer.sslCertificate
) will cause the server to require SSL instead of regular TCP (i.e. the wss://
protocol).
sslCertificate:X509Certificate
When set to a valid godot.X509Certificate
(along with godot.WebSocketServer.privateKey
) will cause the server to require SSL instead of regular TCP (i.e. the wss://
protocol).
Methods
disconnectPeer(id:Int, ?code:Int, ?reason:String):Void
Disconnects the peer identified by id
from the server. See godot.WebSocketPeer.close
for more information.
listen(port:Int, ?protocols:Array<String>, ?gdMpApi:Bool):Error
Starts listening on the given port.
You can specify the desired subprotocols via the "protocols" array. If the list empty (default), no sub-protocol will be requested.
If true
is passed as gd_mp_api
, the server will behave like a network peer for the godot.MultiplayerAPI
, connections from non-Godot clients will not work, and data_received
will not be emitted.
If false
is passed instead (default), you must call godot.PacketPeer
functions (put_packet
, get_packet
, etc.), on the godot.WebSocketPeer
returned via get_peer(id)
to communicate with the peer with given id
(e.g. get_peer(id).get_available_packet_count
).
Parameters:
protocols | If the parameter is null, then the default value is Array.Empty<string>() |
---|