class_websocketserver.rst 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the WebSocketServer.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_WebSocketServer:
  5. WebSocketServer
  6. ===============
  7. **Inherits:** :ref:`WebSocketMultiplayerPeer<class_websocketmultiplayerpeer>` **<** :ref:`NetworkedMultiplayerPeer<class_networkedmultiplayerpeer>` **<** :ref:`PacketPeer<class_packetpeer>` **<** :ref:`Reference<class_reference>` **<** :ref:`Object<class_object>`
  8. **Category:** Core
  9. Brief Description
  10. -----------------
  11. A WebSocket server implementation
  12. Member Functions
  13. ----------------
  14. +----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  15. | void | :ref:`disconnect_peer<class_WebSocketServer_disconnect_peer>` **(** :ref:`int<class_int>` id **)** |
  16. +----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  17. | :ref:`String<class_string>` | :ref:`get_peer_address<class_WebSocketServer_get_peer_address>` **(** :ref:`int<class_int>` id **)** const |
  18. +----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`int<class_int>` | :ref:`get_peer_port<class_WebSocketServer_get_peer_port>` **(** :ref:`int<class_int>` id **)** const |
  20. +----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`bool<class_bool>` | :ref:`has_peer<class_WebSocketServer_has_peer>` **(** :ref:`int<class_int>` id **)** const |
  22. +----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`bool<class_bool>` | :ref:`is_listening<class_WebSocketServer_is_listening>` **(** **)** const |
  24. +----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`Error<enum_@globalscope_error>` | :ref:`listen<class_WebSocketServer_listen>` **(** :ref:`int<class_int>` port, :ref:`PoolStringArray<class_poolstringarray>` protocols=PoolStringArray( ), :ref:`bool<class_bool>` gd_mp_api=false **)** |
  26. +----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | void | :ref:`stop<class_WebSocketServer_stop>` **(** **)** |
  28. +----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. Signals
  30. -------
  31. .. _class_WebSocketServer_client_connected:
  32. - **client_connected** **(** :ref:`int<class_int>` id, :ref:`String<class_string>` protocol **)**
  33. Emitted when a new client connects. "protocol" will be the sub-protocol agreed with the client.
  34. .. _class_WebSocketServer_client_disconnected:
  35. - **client_disconnected** **(** :ref:`int<class_int>` id **)**
  36. Emitted when a client disconnects.
  37. .. _class_WebSocketServer_data_received:
  38. - **data_received** **(** :ref:`int<class_int>` id **)**
  39. Emitted when a new message is received. Note: This signal is NOT emitted when used as high level multiplayer peer.
  40. Description
  41. -----------
  42. This class implements a WebSocket server that can also support the high level multiplayer API.
  43. After starting the server (:ref:`listen<class_WebSocketServer_listen>`), you will need to :ref:`NetworkedMultiplayerPeer.poll<class_NetworkedMultiplayerPeer_poll>` it at regular intervals (e.g. inside :ref:`Node._process<class_Node__process>`). When clients connect, disconnect, or send data, you will receive the appropriate signal.
  44. Note: This class will not work in HTML5 exports due to browser restrictions.
  45. Member Function Description
  46. ---------------------------
  47. .. _class_WebSocketServer_disconnect_peer:
  48. - void **disconnect_peer** **(** :ref:`int<class_int>` id **)**
  49. Disconnects the given peer.
  50. .. _class_WebSocketServer_get_peer_address:
  51. - :ref:`String<class_string>` **get_peer_address** **(** :ref:`int<class_int>` id **)** const
  52. Returns the IP address of the given peer.
  53. .. _class_WebSocketServer_get_peer_port:
  54. - :ref:`int<class_int>` **get_peer_port** **(** :ref:`int<class_int>` id **)** const
  55. Returns the remote port of the given peer.
  56. .. _class_WebSocketServer_has_peer:
  57. - :ref:`bool<class_bool>` **has_peer** **(** :ref:`int<class_int>` id **)** const
  58. Returns ``true`` if a peer with the given ID is connected.
  59. .. _class_WebSocketServer_is_listening:
  60. - :ref:`bool<class_bool>` **is_listening** **(** **)** const
  61. Returns ``true`` if the server is actively listening on a port.
  62. .. _class_WebSocketServer_listen:
  63. - :ref:`Error<enum_@globalscope_error>` **listen** **(** :ref:`int<class_int>` port, :ref:`PoolStringArray<class_poolstringarray>` protocols=PoolStringArray( ), :ref:`bool<class_bool>` gd_mp_api=false **)**
  64. Start listening on the given port.
  65. You can specify the desired subprotocols via the "protocols" array. If the list empty (default), "binary" will be used.
  66. You can use this server as a network peer for :ref:`MultiplayerAPI<class_multiplayerapi>` by passing true as "gd_mp_api". Note: :ref:`data_received<class_WebSocketServer_data_received>` will not be fired and clients other than Godot will not work in this case.
  67. .. _class_WebSocketServer_stop:
  68. - void **stop** **(** **)**
  69. Stop the server and clear its state.