WebSocketServer.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="WebSocketServer" inherits="WebSocketMultiplayerPeer" version="3.3">
  3. <brief_description>
  4. A WebSocket server implementation.
  5. </brief_description>
  6. <description>
  7. This class implements a WebSocket server that can also support the high-level multiplayer API.
  8. After starting the server ([method listen]), you will need to [method NetworkedMultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]). When clients connect, disconnect, or send data, you will receive the appropriate signal.
  9. [b]Note:[/b] Not available in HTML5 exports.
  10. </description>
  11. <tutorials>
  12. </tutorials>
  13. <methods>
  14. <method name="disconnect_peer">
  15. <return type="void" />
  16. <argument index="0" name="id" type="int" />
  17. <argument index="1" name="code" type="int" default="1000" />
  18. <argument index="2" name="reason" type="String" default="&quot;&quot;" />
  19. <description>
  20. Disconnects the peer identified by [code]id[/code] from the server. See [method WebSocketPeer.close] for more information.
  21. </description>
  22. </method>
  23. <method name="get_peer_address" qualifiers="const">
  24. <return type="String" />
  25. <argument index="0" name="id" type="int" />
  26. <description>
  27. Returns the IP address of the given peer.
  28. </description>
  29. </method>
  30. <method name="get_peer_port" qualifiers="const">
  31. <return type="int" />
  32. <argument index="0" name="id" type="int" />
  33. <description>
  34. Returns the remote port of the given peer.
  35. </description>
  36. </method>
  37. <method name="has_peer" qualifiers="const">
  38. <return type="bool" />
  39. <argument index="0" name="id" type="int" />
  40. <description>
  41. Returns [code]true[/code] if a peer with the given ID is connected.
  42. </description>
  43. </method>
  44. <method name="is_listening" qualifiers="const">
  45. <return type="bool" />
  46. <description>
  47. Returns [code]true[/code] if the server is actively listening on a port.
  48. </description>
  49. </method>
  50. <method name="listen">
  51. <return type="int" enum="Error" />
  52. <argument index="0" name="port" type="int" />
  53. <argument index="1" name="protocols" type="PoolStringArray" default="PoolStringArray( )" />
  54. <argument index="2" name="gd_mp_api" type="bool" default="false" />
  55. <description>
  56. Starts listening on the given port.
  57. You can specify the desired subprotocols via the "protocols" array. If the list empty (default), no sub-protocol will be requested.
  58. If [code]true[/code] is passed as [code]gd_mp_api[/code], the server will behave like a network peer for the [MultiplayerAPI], connections from non-Godot clients will not work, and [signal data_received] will not be emitted.
  59. If [code]false[/code] is passed instead (default), you must call [PacketPeer] functions ([code]put_packet[/code], [code]get_packet[/code], etc.), on the [WebSocketPeer] returned via [code]get_peer(id)[/code] to communicate with the peer with given [code]id[/code] (e.g. [code]get_peer(id).get_available_packet_count[/code]).
  60. </description>
  61. </method>
  62. <method name="stop">
  63. <return type="void" />
  64. <description>
  65. Stops the server and clear its state.
  66. </description>
  67. </method>
  68. </methods>
  69. <members>
  70. <member name="bind_ip" type="String" setter="set_bind_ip" getter="get_bind_ip" default="&quot;*&quot;">
  71. When not set to [code]*[/code] will restrict incoming connections to the specified IP address. Setting [code]bind_ip[/code] to [code]127.0.0.1[/code] will cause the server to listen only to the local host.
  72. </member>
  73. <member name="ca_chain" type="X509Certificate" setter="set_ca_chain" getter="get_ca_chain">
  74. When using SSL (see [member private_key] and [member ssl_certificate]), you can set this to a valid [X509Certificate] to be provided as additional CA chain information during the SSL handshake.
  75. </member>
  76. <member name="private_key" type="CryptoKey" setter="set_private_key" getter="get_private_key">
  77. When set to a valid [CryptoKey] (along with [member ssl_certificate]) will cause the server to require SSL instead of regular TCP (i.e. the [code]wss://[/code] protocol).
  78. </member>
  79. <member name="ssl_certificate" type="X509Certificate" setter="set_ssl_certificate" getter="get_ssl_certificate">
  80. When set to a valid [X509Certificate] (along with [member private_key]) will cause the server to require SSL instead of regular TCP (i.e. the [code]wss://[/code] protocol).
  81. </member>
  82. </members>
  83. <signals>
  84. <signal name="client_close_request">
  85. <argument index="0" name="id" type="int" />
  86. <argument index="1" name="code" type="int" />
  87. <argument index="2" name="reason" type="String" />
  88. <description>
  89. Emitted when a client requests a clean close. You should keep polling until you get a [signal client_disconnected] signal with the same [code]id[/code] to achieve the clean close. See [method WebSocketPeer.close] for more details.
  90. </description>
  91. </signal>
  92. <signal name="client_connected">
  93. <argument index="0" name="id" type="int" />
  94. <argument index="1" name="protocol" type="String" />
  95. <description>
  96. Emitted when a new client connects. "protocol" will be the sub-protocol agreed with the client.
  97. </description>
  98. </signal>
  99. <signal name="client_disconnected">
  100. <argument index="0" name="id" type="int" />
  101. <argument index="1" name="was_clean_close" type="bool" />
  102. <description>
  103. Emitted when a client disconnects. [code]was_clean_close[/code] will be [code]true[/code] if the connection was shutdown cleanly.
  104. </description>
  105. </signal>
  106. <signal name="data_received">
  107. <argument index="0" name="id" type="int" />
  108. <description>
  109. Emitted when a new message is received.
  110. [b]Note:[/b] This signal is [i]not[/i] emitted when used as high-level multiplayer peer.
  111. </description>
  112. </signal>
  113. </signals>
  114. <constants>
  115. </constants>
  116. </class>