:github_url: hide .. Generated automatically by doc/tools/make_rst.py in Godot's source tree. .. DO NOT EDIT THIS FILE, but the WebSocketServer.xml source instead. .. The source is found in doc/classes or modules//doc_classes. .. _class_WebSocketServer: WebSocketServer =============== **Inherits:** :ref:`WebSocketMultiplayerPeer` **<** :ref:`NetworkedMultiplayerPeer` **<** :ref:`PacketPeer` **<** :ref:`Reference` **<** :ref:`Object` A WebSocket server implementation. Description ----------- This class implements a WebSocket server that can also support the high-level multiplayer API. After starting the server (:ref:`listen`), you will need to :ref:`NetworkedMultiplayerPeer.poll` it at regular intervals (e.g. inside :ref:`Node._process`). When clients connect, disconnect, or send data, you will receive the appropriate signal. **Note:** Not available in HTML5 exports. Properties ---------- +-----------------------------------------------+----------------------------------------------------------------------------+---------+ | :ref:`String` | :ref:`bind_ip` | ``"*"`` | +-----------------------------------------------+----------------------------------------------------------------------------+---------+ | :ref:`X509Certificate` | :ref:`ca_chain` | | +-----------------------------------------------+----------------------------------------------------------------------------+---------+ | :ref:`float` | :ref:`handshake_timeout` | ``3.0`` | +-----------------------------------------------+----------------------------------------------------------------------------+---------+ | :ref:`CryptoKey` | :ref:`private_key` | | +-----------------------------------------------+----------------------------------------------------------------------------+---------+ | :ref:`X509Certificate` | :ref:`ssl_certificate` | | +-----------------------------------------------+----------------------------------------------------------------------------+---------+ Methods ------- +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`disconnect_peer` **(** :ref:`int` id, :ref:`int` code=1000, :ref:`String` reason="" **)** | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`String` | :ref:`get_peer_address` **(** :ref:`int` id **)** |const| | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_peer_port` **(** :ref:`int` id **)** |const| | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`has_peer` **(** :ref:`int` id **)** |const| | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_listening` **(** **)** |const| | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`listen` **(** :ref:`int` port, :ref:`PoolStringArray` protocols=PoolStringArray( ), :ref:`bool` gd_mp_api=false **)** | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`stop` **(** **)** | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Signals ------- .. _class_WebSocketServer_signal_client_close_request: - **client_close_request** **(** :ref:`int` id, :ref:`int` code, :ref:`String` reason **)** Emitted when a client requests a clean close. You should keep polling until you get a :ref:`client_disconnected` signal with the same ``id`` to achieve the clean close. See :ref:`WebSocketPeer.close` for more details. ---- .. _class_WebSocketServer_signal_client_connected: - **client_connected** **(** :ref:`int` id, :ref:`String` protocol **)** Emitted when a new client connects. "protocol" will be the sub-protocol agreed with the client. ---- .. _class_WebSocketServer_signal_client_disconnected: - **client_disconnected** **(** :ref:`int` id, :ref:`bool` was_clean_close **)** Emitted when a client disconnects. ``was_clean_close`` will be ``true`` if the connection was shutdown cleanly. ---- .. _class_WebSocketServer_signal_data_received: - **data_received** **(** :ref:`int` id **)** Emitted when a new message is received. **Note:** This signal is *not* emitted when used as high-level multiplayer peer. Property Descriptions --------------------- .. _class_WebSocketServer_property_bind_ip: - :ref:`String` **bind_ip** +-----------+--------------------+ | *Default* | ``"*"`` | +-----------+--------------------+ | *Setter* | set_bind_ip(value) | +-----------+--------------------+ | *Getter* | get_bind_ip() | +-----------+--------------------+ 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. ---- .. _class_WebSocketServer_property_ca_chain: - :ref:`X509Certificate` **ca_chain** +----------+---------------------+ | *Setter* | set_ca_chain(value) | +----------+---------------------+ | *Getter* | get_ca_chain() | +----------+---------------------+ When using SSL (see :ref:`private_key` and :ref:`ssl_certificate`), you can set this to a valid :ref:`X509Certificate` to be provided as additional CA chain information during the SSL handshake. ---- .. _class_WebSocketServer_property_handshake_timeout: - :ref:`float` **handshake_timeout** +-----------+------------------------------+ | *Default* | ``3.0`` | +-----------+------------------------------+ | *Setter* | set_handshake_timeout(value) | +-----------+------------------------------+ | *Getter* | get_handshake_timeout() | +-----------+------------------------------+ 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. ---- .. _class_WebSocketServer_property_private_key: - :ref:`CryptoKey` **private_key** +----------+------------------------+ | *Setter* | set_private_key(value) | +----------+------------------------+ | *Getter* | get_private_key() | +----------+------------------------+ When set to a valid :ref:`CryptoKey` (along with :ref:`ssl_certificate`) will cause the server to require SSL instead of regular TCP (i.e. the ``wss://`` protocol). ---- .. _class_WebSocketServer_property_ssl_certificate: - :ref:`X509Certificate` **ssl_certificate** +----------+----------------------------+ | *Setter* | set_ssl_certificate(value) | +----------+----------------------------+ | *Getter* | get_ssl_certificate() | +----------+----------------------------+ When set to a valid :ref:`X509Certificate` (along with :ref:`private_key`) will cause the server to require SSL instead of regular TCP (i.e. the ``wss://`` protocol). Method Descriptions ------------------- .. _class_WebSocketServer_method_disconnect_peer: - void **disconnect_peer** **(** :ref:`int` id, :ref:`int` code=1000, :ref:`String` reason="" **)** Disconnects the peer identified by ``id`` from the server. See :ref:`WebSocketPeer.close` for more information. ---- .. _class_WebSocketServer_method_get_peer_address: - :ref:`String` **get_peer_address** **(** :ref:`int` id **)** |const| Returns the IP address of the given peer. ---- .. _class_WebSocketServer_method_get_peer_port: - :ref:`int` **get_peer_port** **(** :ref:`int` id **)** |const| Returns the remote port of the given peer. ---- .. _class_WebSocketServer_method_has_peer: - :ref:`bool` **has_peer** **(** :ref:`int` id **)** |const| Returns ``true`` if a peer with the given ID is connected. ---- .. _class_WebSocketServer_method_is_listening: - :ref:`bool` **is_listening** **(** **)** |const| Returns ``true`` if the server is actively listening on a port. ---- .. _class_WebSocketServer_method_listen: - :ref:`Error` **listen** **(** :ref:`int` port, :ref:`PoolStringArray` protocols=PoolStringArray( ), :ref:`bool` gd_mp_api=false **)** 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 :ref:`MultiplayerAPI`, connections from non-Godot clients will not work, and :ref:`data_received` will not be emitted. If ``false`` is passed instead (default), you must call :ref:`PacketPeer` functions (``put_packet``, ``get_packet``, etc.), on the :ref:`WebSocketPeer` returned via ``get_peer(id)`` to communicate with the peer with given ``id`` (e.g. ``get_peer(id).get_available_packet_count``). ---- .. _class_WebSocketServer_method_stop: - void **stop** **(** **)** Stops the server and clear its state. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`