WebSocketServer

    Category: Core

    A WebSocket server implementation

    • client_close_request ( id, int code, reason )

    Emitted when a client requests a clean close. You should keep polling until you get a client_disconnected signal with the same to achieve the clean close. See for more details.


    • client_connected ( int id, protocol )

    Emitted when a new client connects. “protocol” will be the sub-protocol agreed with the client.


    • client_disconnected ( int id, was_clean_close )

    Emitted when a client disconnects. was_clean_close will be true if the connection was shutdown cleanly.


    • data_received ( int id )

    This class implements a WebSocket server that can also support the high level multiplayer API.

    After starting the server (), you will need to NetworkedMultiplayerPeer.poll it at regular intervals (e.g. inside ). 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.

    Disconnects the peer identified by id from the server. See WebSocketPeer.close for more info.


    • get_peer_address ( int id ) const

    Returns the IP address of the given peer.


    • get_peer_port ( int id ) const

    • has_peer ( int id ) const

    Returns if a peer with the given ID is connected.


    • is_listening ( ) const

    Returns true if the server is actively listening on a port.


    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.

    If true is passed as gd_mp_api, the server will behave like a network peer for the MultiplayerAPI, connections from non Godot clients will not work, and will not be emitted.


    • void stop ( )

    Stop the server and clear its state.