2
0

WebSocketServer.xml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="WebSocketServer" inherits="WebSocketMultiplayerPeer" version="4.0">
  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 MultiplayerPeer.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. [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android.
  11. </description>
  12. <tutorials>
  13. </tutorials>
  14. <methods>
  15. <method name="disconnect_peer">
  16. <return type="void" />
  17. <argument index="0" name="id" type="int" />
  18. <argument index="1" name="code" type="int" default="1000" />
  19. <argument index="2" name="reason" type="String" default="&quot;&quot;" />
  20. <description>
  21. Disconnects the peer identified by [code]id[/code] from the server. See [method WebSocketPeer.close] for more information.
  22. </description>
  23. </method>
  24. <method name="get_peer_address" qualifiers="const">
  25. <return type="String" />
  26. <argument index="0" name="id" type="int" />
  27. <description>
  28. Returns the IP address of the given peer.
  29. </description>
  30. </method>
  31. <method name="get_peer_port" qualifiers="const">
  32. <return type="int" />
  33. <argument index="0" name="id" type="int" />
  34. <description>
  35. Returns the remote port of the given peer.
  36. </description>
  37. </method>
  38. <method name="has_peer" qualifiers="const">
  39. <return type="bool" />
  40. <argument index="0" name="id" type="int" />
  41. <description>
  42. Returns [code]true[/code] if a peer with the given ID is connected.
  43. </description>
  44. </method>
  45. <method name="is_listening" qualifiers="const">
  46. <return type="bool" />
  47. <description>
  48. Returns [code]true[/code] if the server is actively listening on a port.
  49. </description>
  50. </method>
  51. <method name="listen">
  52. <return type="int" enum="Error" />
  53. <argument index="0" name="port" type="int" />
  54. <argument index="1" name="protocols" type="PackedStringArray" default="PackedStringArray()" />
  55. <argument index="2" name="gd_mp_api" type="bool" default="false" />
  56. <description>
  57. Starts listening on the given port.
  58. You can specify the desired subprotocols via the "protocols" array. If the list empty (default), no sub-protocol will be requested.
  59. If [code]true[/code] is passed as [code]gd_mp_api[/code], the server will behave like a multiplayer peer for the [MultiplayerAPI], connections from non-Godot clients will not work, and [signal data_received] will not be emitted.
  60. 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]).
  61. </description>
  62. </method>
  63. <method name="stop">
  64. <return type="void" />
  65. <description>
  66. Stops the server and clear its state.
  67. </description>
  68. </method>
  69. </methods>
  70. <members>
  71. <member name="bind_ip" type="String" setter="set_bind_ip" getter="get_bind_ip" default="&quot;*&quot;">
  72. 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.
  73. </member>
  74. <member name="ca_chain" type="X509Certificate" setter="set_ca_chain" getter="get_ca_chain">
  75. 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.
  76. </member>
  77. <member name="handshake_timeout" type="float" setter="set_handshake_timeout" getter="get_handshake_timeout" default="3.0">
  78. 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.
  79. </member>
  80. <member name="private_key" type="CryptoKey" setter="set_private_key" getter="get_private_key">
  81. 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).
  82. </member>
  83. <member name="ssl_certificate" type="X509Certificate" setter="set_ssl_certificate" getter="get_ssl_certificate">
  84. 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).
  85. </member>
  86. </members>
  87. <signals>
  88. <signal name="client_close_request">
  89. <argument index="0" name="id" type="int" />
  90. <argument index="1" name="code" type="int" />
  91. <argument index="2" name="reason" type="String" />
  92. <description>
  93. 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.
  94. </description>
  95. </signal>
  96. <signal name="client_connected">
  97. <argument index="0" name="id" type="int" />
  98. <argument index="1" name="protocol" type="String" />
  99. <argument index="2" name="resource_name" type="String" />
  100. <description>
  101. Emitted when a new client connects. "protocol" will be the sub-protocol agreed with the client, and "resource_name" will be the resource name of the URI the peer used.
  102. "resource_name" is a path (at the very least a single forward slash) and potentially a query string.
  103. </description>
  104. </signal>
  105. <signal name="client_disconnected">
  106. <argument index="0" name="id" type="int" />
  107. <argument index="1" name="was_clean_close" type="bool" />
  108. <description>
  109. Emitted when a client disconnects. [code]was_clean_close[/code] will be [code]true[/code] if the connection was shutdown cleanly.
  110. </description>
  111. </signal>
  112. <signal name="data_received">
  113. <argument index="0" name="id" type="int" />
  114. <description>
  115. Emitted when a new message is received.
  116. [b]Note:[/b] This signal is [i]not[/i] emitted when used as high-level multiplayer peer.
  117. </description>
  118. </signal>
  119. </signals>
  120. </class>