WebSocketPeer
Category: Core
A class representing a specific WebSocket connection.
enum WriteMode:
- WRITE_MODE_TEXT = 0 — Specify that WebSockets messages should be transferred as text payload (only valid UTF-8 is allowed).
- WRITE_MODE_BINARY = 1 — Specify that WebSockets messages should be transferred as binary payload (any byte combination is allowed).
This class represent a specific WebSocket connection, you can do lower level operations with it.
- void close ( code=1000, String reason=”” )
Close this WebSocket connection. is the status code for the closure (see RFC6455 section 7.4 for a list of valid status codes). is the human readable reason for closing the connection (can be any UTF8 string, must be less than 123 bytes).
Note: To achieve a clean close, you will need to keep polling until either or WebSocketServer.client_disconnected is received.
Note: HTML5 export might not support all status codes. Please refer to browsers-specific documentation for more details.
- get_connected_host ( ) const
Returns the IP Address of the connected peer. (Not available in HTML5 export)
- WriteMode get_write_mode ( ) const
Get the current selected write mode. See .
- bool is_connected_to_host ( ) const
Returns if this peer is currently connected.
- void set_write_mode ( mode )
Sets the socket to use the given WriteMode.
- was_string_packet ( ) const
Returns if the last received packet was sent as a text payload. See WriteMode