WebSocketServer.xml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="WebSocketServer" inherits="WebSocketMultiplayerPeer" category="Core" version="3.1.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. Note: This class will not work in HTML5 exports due to browser restrictions.
  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 info.
  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. Start listening on the given port.
  72. You can specify the desired subprotocols via the "protocols" array. If the list empty (default), "binary" will be used.
  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. Stop the server and clear its state.
  82. </description>
  83. </method>
  84. </methods>
  85. <signals>
  86. <signal name="client_close_request">
  87. <argument index="0" name="id" type="int">
  88. </argument>
  89. <argument index="1" name="code" type="int">
  90. </argument>
  91. <argument index="2" name="reason" type="String">
  92. </argument>
  93. <description>
  94. 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.
  95. </description>
  96. </signal>
  97. <signal name="client_connected">
  98. <argument index="0" name="id" type="int">
  99. </argument>
  100. <argument index="1" name="protocol" type="String">
  101. </argument>
  102. <description>
  103. Emitted when a new client connects. "protocol" will be the sub-protocol agreed with the client.
  104. </description>
  105. </signal>
  106. <signal name="client_disconnected">
  107. <argument index="0" name="id" type="int">
  108. </argument>
  109. <argument index="1" name="was_clean_close" type="bool">
  110. </argument>
  111. <description>
  112. Emitted when a client disconnects. [code]was_clean_close[/code] will be [code]true[/code] if the connection was shutdown cleanly.
  113. </description>
  114. </signal>
  115. <signal name="data_received">
  116. <argument index="0" name="id" type="int">
  117. </argument>
  118. <description>
  119. Emitted when a new message is received. Note: This signal is NOT emitted when used as high level multiplayer peer.
  120. </description>
  121. </signal>
  122. </signals>
  123. <constants>
  124. </constants>
  125. </class>