WebSocketServer.xml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="WebSocketServer" inherits="WebSocketMultiplayerPeer" version="3.2">
  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. </return>
  17. <argument index="0" name="id" type="int">
  18. </argument>
  19. <argument index="1" name="code" type="int" default="1000">
  20. </argument>
  21. <argument index="2" name="reason" type="String" default="&quot;&quot;">
  22. </argument>
  23. <description>
  24. Disconnects the peer identified by [code]id[/code] from the server. See [method WebSocketPeer.close] for more information.
  25. </description>
  26. </method>
  27. <method name="get_peer_address" qualifiers="const">
  28. <return type="String">
  29. </return>
  30. <argument index="0" name="id" type="int">
  31. </argument>
  32. <description>
  33. Returns the IP address of the given peer.
  34. </description>
  35. </method>
  36. <method name="get_peer_port" qualifiers="const">
  37. <return type="int">
  38. </return>
  39. <argument index="0" name="id" type="int">
  40. </argument>
  41. <description>
  42. Returns the remote port of the given peer.
  43. </description>
  44. </method>
  45. <method name="has_peer" qualifiers="const">
  46. <return type="bool">
  47. </return>
  48. <argument index="0" name="id" type="int">
  49. </argument>
  50. <description>
  51. Returns [code]true[/code] if a peer with the given ID is connected.
  52. </description>
  53. </method>
  54. <method name="is_listening" qualifiers="const">
  55. <return type="bool">
  56. </return>
  57. <description>
  58. Returns [code]true[/code] if the server is actively listening on a port.
  59. </description>
  60. </method>
  61. <method name="listen">
  62. <return type="int" enum="Error">
  63. </return>
  64. <argument index="0" name="port" type="int">
  65. </argument>
  66. <argument index="1" name="protocols" type="PoolStringArray" default="PoolStringArray( )">
  67. </argument>
  68. <argument index="2" name="gd_mp_api" type="bool" default="false">
  69. </argument>
  70. <description>
  71. Starts listening on the given port.
  72. You can specify the desired subprotocols via the "protocols" array. If the list empty (default), no sub-protocol will be requested.
  73. 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.
  74. 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]).
  75. </description>
  76. </method>
  77. <method name="stop">
  78. <return type="void">
  79. </return>
  80. <description>
  81. Stops the server and clear its state.
  82. </description>
  83. </method>
  84. </methods>
  85. <members>
  86. <member name="bind_ip" type="String" setter="set_bind_ip" getter="get_bind_ip" default="&quot;*&quot;">
  87. 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.
  88. </member>
  89. <member name="ca_chain" type="X509Certificate" setter="set_ca_chain" getter="get_ca_chain">
  90. 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.
  91. </member>
  92. <member name="private_key" type="CryptoKey" setter="set_private_key" getter="get_private_key">
  93. 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).
  94. </member>
  95. <member name="ssl_certificate" type="X509Certificate" setter="set_ssl_certificate" getter="get_ssl_certificate">
  96. 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).
  97. </member>
  98. </members>
  99. <signals>
  100. <signal name="client_close_request">
  101. <argument index="0" name="id" type="int">
  102. </argument>
  103. <argument index="1" name="code" type="int">
  104. </argument>
  105. <argument index="2" name="reason" type="String">
  106. </argument>
  107. <description>
  108. 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.
  109. </description>
  110. </signal>
  111. <signal name="client_connected">
  112. <argument index="0" name="id" type="int">
  113. </argument>
  114. <argument index="1" name="protocol" type="String">
  115. </argument>
  116. <description>
  117. Emitted when a new client connects. "protocol" will be the sub-protocol agreed with the client.
  118. </description>
  119. </signal>
  120. <signal name="client_disconnected">
  121. <argument index="0" name="id" type="int">
  122. </argument>
  123. <argument index="1" name="was_clean_close" type="bool">
  124. </argument>
  125. <description>
  126. Emitted when a client disconnects. [code]was_clean_close[/code] will be [code]true[/code] if the connection was shutdown cleanly.
  127. </description>
  128. </signal>
  129. <signal name="data_received">
  130. <argument index="0" name="id" type="int">
  131. </argument>
  132. <description>
  133. Emitted when a new message is received.
  134. [b]Note:[/b] This signal is [i]not[/i] emitted when used as high-level multiplayer peer.
  135. </description>
  136. </signal>
  137. </signals>
  138. <constants>
  139. </constants>
  140. </class>