WebSocketServer.xml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="WebSocketServer" inherits="WebSocketMultiplayerPeer" version="3.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
  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="set_extra_headers">
  63. <return type="void" />
  64. <argument index="0" name="headers" type="PoolStringArray" default="PoolStringArray( )" />
  65. <description>
  66. Sets additional headers to be sent to clients during the HTTP handshake.
  67. </description>
  68. </method>
  69. <method name="stop">
  70. <return type="void" />
  71. <description>
  72. Stops the server and clear its state.
  73. </description>
  74. </method>
  75. </methods>
  76. <members>
  77. <member name="bind_ip" type="String" setter="set_bind_ip" getter="get_bind_ip" default="&quot;*&quot;">
  78. 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.
  79. </member>
  80. <member name="ca_chain" type="X509Certificate" setter="set_ca_chain" getter="get_ca_chain">
  81. 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.
  82. </member>
  83. <member name="handshake_timeout" type="float" setter="set_handshake_timeout" getter="get_handshake_timeout" default="3.0">
  84. The time in seconds before a pending client (i.e. a client that has not yet finished the HTTP handshake) is considered stale and forcefully disconnected.
  85. </member>
  86. <member name="private_key" type="CryptoKey" setter="set_private_key" getter="get_private_key">
  87. 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).
  88. </member>
  89. <member name="ssl_certificate" type="X509Certificate" setter="set_ssl_certificate" getter="get_ssl_certificate">
  90. 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).
  91. </member>
  92. </members>
  93. <signals>
  94. <signal name="client_close_request">
  95. <argument index="0" name="id" type="int" />
  96. <argument index="1" name="code" type="int" />
  97. <argument index="2" name="reason" type="String" />
  98. <description>
  99. 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.
  100. </description>
  101. </signal>
  102. <signal name="client_connected">
  103. <argument index="0" name="id" type="int" />
  104. <argument index="1" name="protocol" type="String" />
  105. <description>
  106. Emitted when a new client connects. "protocol" will be the sub-protocol agreed with the client.
  107. </description>
  108. </signal>
  109. <signal name="client_disconnected">
  110. <argument index="0" name="id" type="int" />
  111. <argument index="1" name="was_clean_close" type="bool" />
  112. <description>
  113. Emitted when a client disconnects. [code]was_clean_close[/code] will be [code]true[/code] if the connection was shutdown cleanly.
  114. </description>
  115. </signal>
  116. <signal name="data_received">
  117. <argument index="0" name="id" type="int" />
  118. <description>
  119. Emitted when a new message is received.
  120. [b]Note:[/b] This signal is [i]not[/i] emitted when used as high-level multiplayer peer.
  121. </description>
  122. </signal>
  123. </signals>
  124. <constants>
  125. </constants>
  126. </class>