WebSocketPeer.xml 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="WebSocketPeer" inherits="PacketPeer" version="3.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
  3. <brief_description>
  4. A class representing a specific WebSocket connection.
  5. </brief_description>
  6. <description>
  7. This class represents a specific WebSocket connection, allowing you to do lower level operations with it.
  8. You can choose to write to the socket in binary or text mode, and you can recognize the mode used for writing by the other peer.
  9. </description>
  10. <tutorials>
  11. </tutorials>
  12. <methods>
  13. <method name="close">
  14. <return type="void" />
  15. <argument index="0" name="code" type="int" default="1000" />
  16. <argument index="1" name="reason" type="String" default="&quot;&quot;" />
  17. <description>
  18. Closes this WebSocket connection. [code]code[/code] is the status code for the closure (see RFC 6455 section 7.4 for a list of valid status codes). [code]reason[/code] is the human readable reason for closing the connection (can be any UTF-8 string that's smaller than 123 bytes).
  19. [b]Note:[/b] To achieve a clean close, you will need to keep polling until either [signal WebSocketClient.connection_closed] or [signal WebSocketServer.client_disconnected] is received.
  20. [b]Note:[/b] The HTML5 export might not support all status codes. Please refer to browser-specific documentation for more details.
  21. </description>
  22. </method>
  23. <method name="get_connected_host" qualifiers="const">
  24. <return type="String" />
  25. <description>
  26. Returns the IP address of the connected peer.
  27. [b]Note:[/b] Not available in the HTML5 export.
  28. </description>
  29. </method>
  30. <method name="get_connected_port" qualifiers="const">
  31. <return type="int" />
  32. <description>
  33. Returns the remote port of the connected peer.
  34. [b]Note:[/b] Not available in the HTML5 export.
  35. </description>
  36. </method>
  37. <method name="get_current_outbound_buffered_amount" qualifiers="const">
  38. <return type="int" />
  39. <description>
  40. Returns the current amount of data in the outbound websocket buffer. [b]Note:[/b] HTML5 exports use WebSocket.bufferedAmount, while other platforms use an internal buffer.
  41. </description>
  42. </method>
  43. <method name="get_write_mode" qualifiers="const">
  44. <return type="int" enum="WebSocketPeer.WriteMode" />
  45. <description>
  46. Gets the current selected write mode. See [enum WriteMode].
  47. </description>
  48. </method>
  49. <method name="is_connected_to_host" qualifiers="const">
  50. <return type="bool" />
  51. <description>
  52. Returns [code]true[/code] if this peer is currently connected.
  53. </description>
  54. </method>
  55. <method name="set_no_delay">
  56. <return type="void" />
  57. <argument index="0" name="enabled" type="bool" />
  58. <description>
  59. Disable Nagle's algorithm on the underling TCP socket (default). See [method StreamPeerTCP.set_no_delay] for more information.
  60. [b]Note:[/b] Not available in the HTML5 export.
  61. </description>
  62. </method>
  63. <method name="set_write_mode">
  64. <return type="void" />
  65. <argument index="0" name="mode" type="int" enum="WebSocketPeer.WriteMode" />
  66. <description>
  67. Sets the socket to use the given [enum WriteMode].
  68. </description>
  69. </method>
  70. <method name="was_string_packet" qualifiers="const">
  71. <return type="bool" />
  72. <description>
  73. Returns [code]true[/code] if the last received packet was sent as a text payload. See [enum WriteMode].
  74. </description>
  75. </method>
  76. </methods>
  77. <constants>
  78. <constant name="WRITE_MODE_TEXT" value="0" enum="WriteMode">
  79. Specifies that WebSockets messages should be transferred as text payload (only valid UTF-8 is allowed).
  80. </constant>
  81. <constant name="WRITE_MODE_BINARY" value="1" enum="WriteMode">
  82. Specifies that WebSockets messages should be transferred as binary payload (any byte combination is allowed).
  83. </constant>
  84. </constants>
  85. </class>