class_websocketpeer.rst 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the WebSocketPeer.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_WebSocketPeer:
  6. WebSocketPeer
  7. =============
  8. **Inherits:** :ref:`PacketPeer<class_PacketPeer>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. A class representing a specific WebSocket connection.
  10. Description
  11. -----------
  12. This class represent a specific WebSocket connection, you can do lower level operations with it.
  13. 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.
  14. Methods
  15. -------
  16. +------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  17. | void | :ref:`close<class_WebSocketPeer_method_close>` **(** :ref:`int<class_int>` code=1000, :ref:`String<class_String>` reason="" **)** |
  18. +------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`String<class_String>` | :ref:`get_connected_host<class_WebSocketPeer_method_get_connected_host>` **(** **)** const |
  20. +------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`int<class_int>` | :ref:`get_connected_port<class_WebSocketPeer_method_get_connected_port>` **(** **)** const |
  22. +------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`WriteMode<enum_WebSocketPeer_WriteMode>` | :ref:`get_write_mode<class_WebSocketPeer_method_get_write_mode>` **(** **)** const |
  24. +------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`bool<class_bool>` | :ref:`is_connected_to_host<class_WebSocketPeer_method_is_connected_to_host>` **(** **)** const |
  26. +------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  27. | void | :ref:`set_no_delay<class_WebSocketPeer_method_set_no_delay>` **(** :ref:`bool<class_bool>` enabled **)** |
  28. +------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  29. | void | :ref:`set_write_mode<class_WebSocketPeer_method_set_write_mode>` **(** :ref:`WriteMode<enum_WebSocketPeer_WriteMode>` mode **)** |
  30. +------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`bool<class_bool>` | :ref:`was_string_packet<class_WebSocketPeer_method_was_string_packet>` **(** **)** const |
  32. +------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  33. Enumerations
  34. ------------
  35. .. _enum_WebSocketPeer_WriteMode:
  36. .. _class_WebSocketPeer_constant_WRITE_MODE_TEXT:
  37. .. _class_WebSocketPeer_constant_WRITE_MODE_BINARY:
  38. enum **WriteMode**:
  39. - **WRITE_MODE_TEXT** = **0** --- Specifies that WebSockets messages should be transferred as text payload (only valid UTF-8 is allowed).
  40. - **WRITE_MODE_BINARY** = **1** --- Specifies that WebSockets messages should be transferred as binary payload (any byte combination is allowed).
  41. Method Descriptions
  42. -------------------
  43. .. _class_WebSocketPeer_method_close:
  44. - void **close** **(** :ref:`int<class_int>` code=1000, :ref:`String<class_String>` reason="" **)**
  45. 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).
  46. **Note:** To achieve a clean close, you will need to keep polling until either :ref:`WebSocketClient.connection_closed<class_WebSocketClient_signal_connection_closed>` or :ref:`WebSocketServer.client_disconnected<class_WebSocketServer_signal_client_disconnected>` is received.
  47. **Note:** The HTML5 export might not support all status codes. Please refer to browser-specific documentation for more details.
  48. ----
  49. .. _class_WebSocketPeer_method_get_connected_host:
  50. - :ref:`String<class_String>` **get_connected_host** **(** **)** const
  51. Returns the IP address of the connected peer.
  52. **Note:** Not available in the HTML5 export.
  53. ----
  54. .. _class_WebSocketPeer_method_get_connected_port:
  55. - :ref:`int<class_int>` **get_connected_port** **(** **)** const
  56. Returns the remote port of the connected peer.
  57. **Note:** Not available in the HTML5 export.
  58. ----
  59. .. _class_WebSocketPeer_method_get_write_mode:
  60. - :ref:`WriteMode<enum_WebSocketPeer_WriteMode>` **get_write_mode** **(** **)** const
  61. Gets the current selected write mode. See :ref:`WriteMode<enum_WebSocketPeer_WriteMode>`.
  62. ----
  63. .. _class_WebSocketPeer_method_is_connected_to_host:
  64. - :ref:`bool<class_bool>` **is_connected_to_host** **(** **)** const
  65. Returns ``true`` if this peer is currently connected.
  66. ----
  67. .. _class_WebSocketPeer_method_set_no_delay:
  68. - void **set_no_delay** **(** :ref:`bool<class_bool>` enabled **)**
  69. Disable Nagle's algorithm on the underling TCP socket (default). See :ref:`StreamPeerTCP.set_no_delay<class_StreamPeerTCP_method_set_no_delay>` for more information.
  70. **Note:** Not available in the HTML5 export.
  71. ----
  72. .. _class_WebSocketPeer_method_set_write_mode:
  73. - void **set_write_mode** **(** :ref:`WriteMode<enum_WebSocketPeer_WriteMode>` mode **)**
  74. Sets the socket to use the given :ref:`WriteMode<enum_WebSocketPeer_WriteMode>`.
  75. ----
  76. .. _class_WebSocketPeer_method_was_string_packet:
  77. - :ref:`bool<class_bool>` **was_string_packet** **(** **)** const
  78. Returns ``true`` if the last received packet was sent as a text payload. See :ref:`WriteMode<enum_WebSocketPeer_WriteMode>`.