Inherits: PacketPeer < Reference < Object

A class representing a specific WebSocket connection.


This class represent a specific WebSocket connection, you can do lower level operations with it.

You can choose to write to the socket in binary or text mode, and you can recognize the mode used for writing by the other peer.


voidclose ( int code=1000, String reason=”” )
Stringget_connected_host ( ) const
intget_connected_port ( ) const
WriteModeget_write_mode ( ) const
boolis_connected_to_host ( ) const
voidset_no_delay ( bool enabled )
voidset_write_mode ( WriteMode mode )
boolwas_string_packet ( ) const


enum WriteMode:

  • WRITE_MODE_TEXT = 0 — Specifies that WebSockets messages should be transferred as text payload (only valid UTF-8 is allowed).
  • WRITE_MODE_BINARY = 1 — Specifies that WebSockets messages should be transferred as binary payload (any byte combination is allowed).

Method Descriptions

  • void close ( int code=1000, String reason=”” )

Closes this WebSocket connection. code is the status code for the closure (see RFC 6455 section 7.4 for a list of valid status codes). reason is the human readable reason for closing the connection (can be any UTF-8 string that’s smaller than 123 bytes).

Note: To achieve a clean close, you will need to keep polling until either WebSocketClient.connection_closed or WebSocketServer.client_disconnected is received.

Note: The HTML5 export might not support all status codes. Please refer to browser-specific documentation for more details.

  • String get_connected_host ( ) const

Returns the IP address of the connected peer.

Note: Not available in the HTML5 export.

  • int get_connected_port ( ) const

Returns the remote port of the connected peer.

Note: Not available in the HTML5 export.

Gets the current selected write mode. See WriteMode.

  • bool is_connected_to_host ( ) const

Returns true if this peer is currently connected.

  • void set_no_delay ( bool enabled )

Disable Nagle’s algorithm on the underling TCP socket (default). See StreamPeerTCP.set_no_delay for more information.

Note: Not available in the HTML5 export.

Sets the socket to use the given WriteMode.

  • bool was_string_packet ( ) const

Returns true if the last received packet was sent as a text payload. See WriteMode.

Doc ID missing

Disclaimer: This page has been automaticaly and directly extracted from the official Godot Docs website, the 1970-01-01 at 00:00:00. It’s the English Stable version because it’s what most Godot users should use. The Copyright owners are Juan Linietsky, Ariel Manzur and the Godot community. CC-BY 3.0. Thanks for your patience and generosity.