A WebSocket server implementation
    public class WebSocketServer : WebSocketMultiplayerPeer

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

After starting the server (Listen(int, string[], bool)), you will need to NetworkedMultiplayerPeer.Poll() it at regular intervals (e.g. inside Node._Process(float)). 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.

Inheritance Chain


    public WebSocketServer()


    "client_close_request" (int id, int code, String reason)

Emitted when a client requests a clean close. You should keep polling until you get a client_disconnected signal with the same id to achieve the clean close. See WebSocketPeer.Close(int, string) for more details.

    "client_connected" (int id, String protocol)

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

    "client_disconnected" (int id, bool was_clean_close)

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

    "data_received" (int id)

Emitted when a new message is received. Note: This signal is NOT emitted when used as high level multiplayer peer.


    public void DisconnectPeer(int id, int code = 1000, string reason = "")

Disconnects the peer identified by id from the server. See WebSocketPeer.Close(int, string) for more info.

    public string GetPeerAddress(int id)

Returns the IP address of the given peer.

    public int GetPeerPort(int id)

Returns the remote port of the given peer.

    public bool HasPeer(int id)

Returns true if a peer with the given ID is connected.

    public bool IsListening()

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

    public Error Listen(int port, string[] protocols = null, bool gdMpApi = 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.

If true is passed as gdMpApi, the server will behave like a network peer for the 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 PacketPeer functions (put_packet, get_packet, etc.), on the WebSocketPeer returned via get_peer(ID) to communicate with the peer with given ID (e.g. get_peer(ID).get_available_packet_count).

    public void Stop()

Stop the server and clear its state.