class_websocketclient.rst 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 WebSocketClient.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_WebSocketClient:
  6. WebSocketClient
  7. ===============
  8. **Inherits:** :ref:`WebSocketMultiplayerPeer<class_WebSocketMultiplayerPeer>` **<** :ref:`NetworkedMultiplayerPeer<class_NetworkedMultiplayerPeer>` **<** :ref:`PacketPeer<class_PacketPeer>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. **Category:** Core
  10. Brief Description
  11. -----------------
  12. A WebSocket client implementation
  13. Properties
  14. ----------
  15. +-------------------------+--------------------------------------------------------------+
  16. | :ref:`bool<class_bool>` | :ref:`verify_ssl<class_WebSocketClient_property_verify_ssl>` |
  17. +-------------------------+--------------------------------------------------------------+
  18. Methods
  19. -------
  20. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :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 **)** |
  22. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | void | :ref:`disconnect_from_host<class_WebSocketClient_method_disconnect_from_host>` **(** :ref:`int<class_int>` code=1000, :ref:`String<class_String>` reason="" **)** |
  24. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. Signals
  26. -------
  27. .. _class_WebSocketClient_signal_connection_closed:
  28. - **connection_closed** **(** :ref:`bool<class_bool>` was_clean_close **)**
  29. Emitted when the connection to the server is closed. ``was_clean_close`` will be ``true`` if the connection was shutdown cleanly.
  30. ----
  31. .. _class_WebSocketClient_signal_connection_error:
  32. - **connection_error** **(** **)**
  33. Emitted when the connection to the server fails.
  34. ----
  35. .. _class_WebSocketClient_signal_connection_established:
  36. - **connection_established** **(** :ref:`String<class_String>` protocol **)**
  37. Emitted when a connection with the server is established, ``protocol`` will contain the sub-protocol agreed with the server.
  38. ----
  39. .. _class_WebSocketClient_signal_data_received:
  40. - **data_received** **(** **)**
  41. Emitted when a WebSocket message is received. Note: This signal is NOT emitted when used as high level multiplayer peer.
  42. ----
  43. .. _class_WebSocketClient_signal_server_close_request:
  44. - **server_close_request** **(** :ref:`int<class_int>` code, :ref:`String<class_String>` reason **)**
  45. 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.
  46. Description
  47. -----------
  48. This class implements a WebSocket client compatible with any RFC 6455 complaint WebSocket server.
  49. This client can be optionally used as a network peer for the :ref:`MultiplayerAPI<class_MultiplayerAPI>`.
  50. 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>`).
  51. You will received appropriate signals when connecting, disconnecting, or when new data is available.
  52. Property Descriptions
  53. ---------------------
  54. .. _class_WebSocketClient_property_verify_ssl:
  55. - :ref:`bool<class_bool>` **verify_ssl**
  56. +----------+-------------------------------+
  57. | *Setter* | set_verify_ssl_enabled(value) |
  58. +----------+-------------------------------+
  59. | *Getter* | is_verify_ssl_enabled() |
  60. +----------+-------------------------------+
  61. Enable or disable SSL certificate verification. Note: You must specify the certificates to be used in the project settings for it to work when exported.
  62. Method Descriptions
  63. -------------------
  64. .. _class_WebSocketClient_method_connect_to_url:
  65. - :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 **)**
  66. Connect to the given URL requesting one of the given ``protocols`` as sub-protocol.
  67. 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.
  68. 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)``).
  69. ----
  70. .. _class_WebSocketClient_method_disconnect_from_host:
  71. - void **disconnect_from_host** **(** :ref:`int<class_int>` code=1000, :ref:`String<class_String>` reason="" **)**
  72. Disconnect this client from the connected host. See :ref:`WebSocketPeer.close<class_WebSocketPeer_method_close>` for more info.