summaryrefslogtreecommitdiff
path: root/modules/websocket/doc_classes/WebSocketPeer.xml
blob: 43b765d2fefc63296da9c290eb26ef2b9d21e7cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?xml version="1.0" encoding="UTF-8" ?>
<class name="WebSocketPeer" inherits="PacketPeer" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
	<brief_description>
		A class representing a specific WebSocket connection.
	</brief_description>
	<description>
		This class represents a specific WebSocket connection, allowing you to do lower level operations with it.
		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.
	</description>
	<tutorials>
	</tutorials>
	<methods>
		<method name="close">
			<return type="void" />
			<param index="0" name="code" type="int" default="1000" />
			<param index="1" name="reason" type="String" default="&quot;&quot;" />
			<description>
				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).
				[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.
				[b]Note:[/b] The HTML5 export might not support all status codes. Please refer to browser-specific documentation for more details.
			</description>
		</method>
		<method name="get_connected_host" qualifiers="const">
			<return type="String" />
			<description>
				Returns the IP address of the connected peer.
				[b]Note:[/b] Not available in the HTML5 export.
			</description>
		</method>
		<method name="get_connected_port" qualifiers="const">
			<return type="int" />
			<description>
				Returns the remote port of the connected peer.
				[b]Note:[/b] Not available in the HTML5 export.
			</description>
		</method>
		<method name="get_current_outbound_buffered_amount" qualifiers="const">
			<return type="int" />
			<description>
				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.
			</description>
		</method>
		<method name="get_write_mode" qualifiers="const">
			<return type="int" enum="WebSocketPeer.WriteMode" />
			<description>
				Gets the current selected write mode. See [enum WriteMode].
			</description>
		</method>
		<method name="is_connected_to_host" qualifiers="const">
			<return type="bool" />
			<description>
				Returns [code]true[/code] if this peer is currently connected.
			</description>
		</method>
		<method name="set_no_delay">
			<return type="void" />
			<param index="0" name="enabled" type="bool" />
			<description>
				Disable Nagle's algorithm on the underling TCP socket (default). See [method StreamPeerTCP.set_no_delay] for more information.
				[b]Note:[/b] Not available in the HTML5 export.
			</description>
		</method>
		<method name="set_write_mode">
			<return type="void" />
			<param index="0" name="mode" type="int" enum="WebSocketPeer.WriteMode" />
			<description>
				Sets the socket to use the given [enum WriteMode].
			</description>
		</method>
		<method name="was_string_packet" qualifiers="const">
			<return type="bool" />
			<description>
				Returns [code]true[/code] if the last received packet was sent as a text payload. See [enum WriteMode].
			</description>
		</method>
	</methods>
	<constants>
		<constant name="WRITE_MODE_TEXT" value="0" enum="WriteMode">
			Specifies that WebSockets messages should be transferred as text payload (only valid UTF-8 is allowed).
		</constant>
		<constant name="WRITE_MODE_BINARY" value="1" enum="WriteMode">
			Specifies that WebSockets messages should be transferred as binary payload (any byte combination is allowed).
		</constant>
	</constants>
</class>