class_websocketclient.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/modules/websocket/doc_classes/WebSocketClient.xml.
  6. .. _class_WebSocketClient:
  7. WebSocketClient
  8. ===============
  9. **Inherits:** :ref:`WebSocketMultiplayerPeer<class_WebSocketMultiplayerPeer>` **<** :ref:`NetworkedMultiplayerPeer<class_NetworkedMultiplayerPeer>` **<** :ref:`PacketPeer<class_PacketPeer>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. A WebSocket client implementation.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. This class implements a WebSocket client compatible with any RFC 6455-compliant WebSocket server.
  15. This client can be optionally used as a network peer for the :ref:`MultiplayerAPI<class_MultiplayerAPI>`.
  16. After starting the client (:ref:`connect_to_url<class_WebSocketClient_method_connect_to_url>`), you will need to :ref:`NetworkedMultiplayerPeer.poll<class_NetworkedMultiplayerPeer_method_poll>` it at regular intervals (e.g. inside :ref:`Node._process<class_Node_method__process>`).
  17. You will receive appropriate signals when connecting, disconnecting, or when new data is available.
  18. .. rst-class:: classref-reftable-group
  19. Properties
  20. ----------
  21. .. table::
  22. :widths: auto
  23. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  24. | :ref:`X509Certificate<class_X509Certificate>` | :ref:`trusted_ssl_certificate<class_WebSocketClient_property_trusted_ssl_certificate>` |
  25. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  26. | :ref:`bool<class_bool>` | :ref:`verify_ssl<class_WebSocketClient_property_verify_ssl>` |
  27. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  28. .. rst-class:: classref-reftable-group
  29. Methods
  30. -------
  31. .. table::
  32. :widths: auto
  33. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`connect_to_url<class_WebSocketClient_method_connect_to_url>` **(** :ref:`String<class_String>` url, :ref:`PoolStringArray<class_PoolStringArray>` protocols=PoolStringArray( ), :ref:`bool<class_bool>` gd_mp_api=false, :ref:`PoolStringArray<class_PoolStringArray>` custom_headers=PoolStringArray( ) **)** |
  35. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | void | :ref:`disconnect_from_host<class_WebSocketClient_method_disconnect_from_host>` **(** :ref:`int<class_int>` code=1000, :ref:`String<class_String>` reason="" **)** |
  37. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`String<class_String>` | :ref:`get_connected_host<class_WebSocketClient_method_get_connected_host>` **(** **)** |const| |
  39. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`int<class_int>` | :ref:`get_connected_port<class_WebSocketClient_method_get_connected_port>` **(** **)** |const| |
  41. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. .. rst-class:: classref-section-separator
  43. ----
  44. .. rst-class:: classref-descriptions-group
  45. Signals
  46. -------
  47. .. _class_WebSocketClient_signal_connection_closed:
  48. .. rst-class:: classref-signal
  49. **connection_closed** **(** :ref:`bool<class_bool>` was_clean_close **)**
  50. Emitted when the connection to the server is closed. ``was_clean_close`` will be ``true`` if the connection was shutdown cleanly.
  51. .. rst-class:: classref-item-separator
  52. ----
  53. .. _class_WebSocketClient_signal_connection_error:
  54. .. rst-class:: classref-signal
  55. **connection_error** **(** **)**
  56. Emitted when the connection to the server fails.
  57. .. rst-class:: classref-item-separator
  58. ----
  59. .. _class_WebSocketClient_signal_connection_established:
  60. .. rst-class:: classref-signal
  61. **connection_established** **(** :ref:`String<class_String>` protocol **)**
  62. Emitted when a connection with the server is established, ``protocol`` will contain the sub-protocol agreed with the server.
  63. .. rst-class:: classref-item-separator
  64. ----
  65. .. _class_WebSocketClient_signal_data_received:
  66. .. rst-class:: classref-signal
  67. **data_received** **(** **)**
  68. Emitted when a WebSocket message is received.
  69. \ **Note:** This signal is *not* emitted when used as high-level multiplayer peer.
  70. .. rst-class:: classref-item-separator
  71. ----
  72. .. _class_WebSocketClient_signal_server_close_request:
  73. .. rst-class:: classref-signal
  74. **server_close_request** **(** :ref:`int<class_int>` code, :ref:`String<class_String>` reason **)**
  75. Emitted when the server requests a clean close. You should keep polling until you get a :ref:`connection_closed<class_WebSocketClient_signal_connection_closed>` signal to achieve the clean close. See :ref:`WebSocketPeer.close<class_WebSocketPeer_method_close>` for more details.
  76. .. rst-class:: classref-section-separator
  77. ----
  78. .. rst-class:: classref-descriptions-group
  79. Property Descriptions
  80. ---------------------
  81. .. _class_WebSocketClient_property_trusted_ssl_certificate:
  82. .. rst-class:: classref-property
  83. :ref:`X509Certificate<class_X509Certificate>` **trusted_ssl_certificate**
  84. .. rst-class:: classref-property-setget
  85. - void **set_trusted_ssl_certificate** **(** :ref:`X509Certificate<class_X509Certificate>` value **)**
  86. - :ref:`X509Certificate<class_X509Certificate>` **get_trusted_ssl_certificate** **(** **)**
  87. If specified, this :ref:`X509Certificate<class_X509Certificate>` will be the only one accepted when connecting to an SSL host. Any other certificate provided by the server will be regarded as invalid.
  88. \ **Note:** Specifying a custom ``trusted_ssl_certificate`` is not supported in HTML5 exports due to browsers restrictions.
  89. .. rst-class:: classref-item-separator
  90. ----
  91. .. _class_WebSocketClient_property_verify_ssl:
  92. .. rst-class:: classref-property
  93. :ref:`bool<class_bool>` **verify_ssl**
  94. .. rst-class:: classref-property-setget
  95. - void **set_verify_ssl_enabled** **(** :ref:`bool<class_bool>` value **)**
  96. - :ref:`bool<class_bool>` **is_verify_ssl_enabled** **(** **)**
  97. If ``true``, SSL certificate verification is enabled.
  98. \ **Note:** You must specify the certificates to be used in the Project Settings for it to work when exported.
  99. .. rst-class:: classref-section-separator
  100. ----
  101. .. rst-class:: classref-descriptions-group
  102. Method Descriptions
  103. -------------------
  104. .. _class_WebSocketClient_method_connect_to_url:
  105. .. rst-class:: classref-method
  106. :ref:`Error<enum_@GlobalScope_Error>` **connect_to_url** **(** :ref:`String<class_String>` url, :ref:`PoolStringArray<class_PoolStringArray>` protocols=PoolStringArray( ), :ref:`bool<class_bool>` gd_mp_api=false, :ref:`PoolStringArray<class_PoolStringArray>` custom_headers=PoolStringArray( ) **)**
  107. Connects to the given URL requesting one of the given ``protocols`` as sub-protocol. If the list empty (default), no sub-protocol will be requested.
  108. If ``true`` is passed as ``gd_mp_api``, the client will behave like a network peer for the :ref:`MultiplayerAPI<class_MultiplayerAPI>`, connections to non-Godot servers will not work, and :ref:`data_received<class_WebSocketClient_signal_data_received>` will not be emitted.
  109. If ``false`` is passed instead (default), you must call :ref:`PacketPeer<class_PacketPeer>` functions (``put_packet``, ``get_packet``, etc.) on the :ref:`WebSocketPeer<class_WebSocketPeer>` returned via ``get_peer(1)`` and not on this object directly (e.g. ``get_peer(1).put_packet(data)``).
  110. You can optionally pass a list of ``custom_headers`` to be added to the handshake HTTP request.
  111. \ **Note:** To avoid mixed content warnings or errors in HTML5, you may have to use a ``url`` that starts with ``wss://`` (secure) instead of ``ws://``. When doing so, make sure to use the fully qualified domain name that matches the one defined in the server's SSL certificate. Do not connect directly via the IP address for ``wss://`` connections, as it won't match with the SSL certificate.
  112. \ **Note:** Specifying ``custom_headers`` is not supported in HTML5 exports due to browsers restrictions.
  113. .. rst-class:: classref-item-separator
  114. ----
  115. .. _class_WebSocketClient_method_disconnect_from_host:
  116. .. rst-class:: classref-method
  117. void **disconnect_from_host** **(** :ref:`int<class_int>` code=1000, :ref:`String<class_String>` reason="" **)**
  118. Disconnects this client from the connected host. See :ref:`WebSocketPeer.close<class_WebSocketPeer_method_close>` for more information.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_WebSocketClient_method_get_connected_host:
  122. .. rst-class:: classref-method
  123. :ref:`String<class_String>` **get_connected_host** **(** **)** |const|
  124. Return the IP address of the currently connected host.
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_WebSocketClient_method_get_connected_port:
  128. .. rst-class:: classref-method
  129. :ref:`int<class_int>` **get_connected_port** **(** **)** |const|
  130. Return the IP port of the currently connected host.
  131. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  132. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  133. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  134. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`