WebSocketServer.xml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="WebSocketServer" inherits="WebSocketMultiplayerPeer" category="Core" version="3.1">
  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. Note: This class will not work in HTML5 exports due to browser restrictions.
  10. </description>
  11. <tutorials>
  12. </tutorials>
  13. <demos>
  14. </demos>
  15. <methods>
  16. <method name="disconnect_peer">
  17. <return type="void">
  18. </return>
  19. <argument index="0" name="id" type="int">
  20. </argument>
  21. <argument index="1" name="code" type="int" default="1000">
  22. </argument>
  23. <argument index="2" name="reason" type="String" default="&quot;&quot;">
  24. </argument>
  25. <description>
  26. Disconnects the peer identified by [code]id[/code] from the server. See [method WebSocketPeer.close] for more info.
  27. </description>
  28. </method>
  29. <method name="get_peer_address" qualifiers="const">
  30. <return type="String">
  31. </return>
  32. <argument index="0" name="id" type="int">
  33. </argument>
  34. <description>
  35. Returns the IP address of the given peer.
  36. </description>
  37. </method>
  38. <method name="get_peer_port" qualifiers="const">
  39. <return type="int">
  40. </return>
  41. <argument index="0" name="id" type="int">
  42. </argument>
  43. <description>
  44. Returns the remote port of the given peer.
  45. </description>
  46. </method>
  47. <method name="has_peer" qualifiers="const">
  48. <return type="bool">
  49. </return>
  50. <argument index="0" name="id" type="int">
  51. </argument>
  52. <description>
  53. Returns [code]true[/code] if a peer with the given ID is connected.
  54. </description>
  55. </method>
  56. <method name="is_listening" qualifiers="const">
  57. <return type="bool">
  58. </return>
  59. <description>
  60. Returns [code]true[/code] if the server is actively listening on a port.
  61. </description>
  62. </method>
  63. <method name="listen">
  64. <return type="int" enum="Error">
  65. </return>
  66. <argument index="0" name="port" type="int">
  67. </argument>
  68. <argument index="1" name="protocols" type="PoolStringArray" default="PoolStringArray( )">
  69. </argument>
  70. <argument index="2" name="gd_mp_api" type="bool" default="false">
  71. </argument>
  72. <description>
  73. Start listening on the given port.
  74. You can specify the desired subprotocols via the "protocols" array. If the list empty (default), "binary" will be used.
  75. 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.
  76. 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]).
  77. </description>
  78. </method>
  79. <method name="stop">
  80. <return type="void">
  81. </return>
  82. <description>
  83. Stop the server and clear its state.
  84. </description>
  85. </method>
  86. </methods>
  87. <signals>
  88. <signal name="client_close_request">
  89. <argument index="0" name="id" type="int">
  90. </argument>
  91. <argument index="1" name="code" type="int">
  92. </argument>
  93. <argument index="2" name="reason" type="String">
  94. </argument>
  95. <description>
  96. 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.
  97. </description>
  98. </signal>
  99. <signal name="client_connected">
  100. <argument index="0" name="id" type="int">
  101. </argument>
  102. <argument index="1" name="protocol" type="String">
  103. </argument>
  104. <description>
  105. Emitted when a new client connects. "protocol" will be the sub-protocol agreed with the client.
  106. </description>
  107. </signal>
  108. <signal name="client_disconnected">
  109. <argument index="0" name="id" type="int">
  110. </argument>
  111. <argument index="1" name="was_clean_close" type="bool">
  112. </argument>
  113. <description>
  114. Emitted when a client disconnects. [code]was_clean_close[/code] will be [code]true[/code] if the connection was shutdown cleanly.
  115. </description>
  116. </signal>
  117. <signal name="data_received">
  118. <argument index="0" name="id" type="int">
  119. </argument>
  120. <description>
  121. Emitted when a new message is received. Note: This signal is NOT emitted when used as high level multiplayer peer.
  122. </description>
  123. </signal>
  124. </signals>
  125. <constants>
  126. </constants>
  127. </class>