.. Generated automatically by doc/tools/makerst.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` **Category:** Core Brief Description ----------------- A WebSocket server implementation Member Functions ---------------- +----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`disconnect_peer` **(** :ref:`int` id **)** | +----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :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_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_client_disconnected: - **client_disconnected** **(** :ref:`int` id **)** Emitted when a client disconnects. .. _class_WebSocketServer_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. 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: This class will not work in HTML5 exports due to browser restrictions. Member Function Description --------------------------- .. _class_WebSocketServer_disconnect_peer: - void **disconnect_peer** **(** :ref:`int` id **)** Disconnects the given peer. .. _class_WebSocketServer_get_peer_address: - :ref:`String` **get_peer_address** **(** :ref:`int` id **)** const Returns the IP address of the given peer. .. _class_WebSocketServer_get_peer_port: - :ref:`int` **get_peer_port** **(** :ref:`int` id **)** const Returns the remote port of the given peer. .. _class_WebSocketServer_has_peer: - :ref:`bool` **has_peer** **(** :ref:`int` id **)** const Returns ``true`` if a peer with the given ID is connected. .. _class_WebSocketServer_is_listening: - :ref:`bool` **is_listening** **(** **)** const Returns ``true`` if the server is actively listening on a port. .. _class_WebSocketServer_listen: - :ref:`Error` **listen** **(** :ref:`int` port, :ref:`PoolStringArray` protocols=PoolStringArray( ), :ref:`bool` gd_mp_api=false **)** Start listening on the given port. You can specify the desired subprotocols via the "protocols" array. If the list empty (default), "binary" will be used. You can use this server as a network peer for :ref:`MultiplayerAPI` by passing true as "gd_mp_api". Note: :ref:`data_received` will not be fired and clients other than Godot will not work in this case. .. _class_WebSocketServer_stop: - void **stop** **(** **)** Stop the server and clear its state.