summaryrefslogtreecommitdiff
path: root/modules/enet/doc_classes/ENetConnection.xml
blob: d6b0553eba34edb4e7e216151c4b4cfae873ac57 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?xml version="1.0" encoding="UTF-8" ?>
<class name="ENetConnection" inherits="RefCounted" version="4.0">
	<brief_description>
		A wrapper class for an [url=http://enet.bespin.org/group__host.html]ENetHost[/url].
	</brief_description>
	<description>
		ENet's purpose is to provide a relatively thin, simple and robust network communication layer on top of UDP (User Datagram Protocol).
	</description>
	<tutorials>
		<link title="API documentation on the ENet website">http://enet.bespin.org/usergroup0.html</link>
	</tutorials>
	<methods>
		<method name="bandwidth_limit">
			<return type="void" />
			<argument index="0" name="in_bandwidth" type="int" default="0" />
			<argument index="1" name="out_bandwidth" type="int" default="0" />
			<description>
				Adjusts the bandwidth limits of a host.
			</description>
		</method>
		<method name="broadcast">
			<return type="void" />
			<argument index="0" name="channel" type="int" />
			<argument index="1" name="packet" type="PackedByteArray" />
			<argument index="2" name="flags" type="int" />
			<description>
				Queues a [code]packet[/code] to be sent to all peers associated with the host over the specified [code]channel[/code]. See [ENetPacketPeer] [code]FLAG_*[/code] constants for available packet flags.
			</description>
		</method>
		<method name="channel_limit">
			<return type="void" />
			<argument index="0" name="limit" type="int" />
			<description>
				Limits the maximum allowed channels of future incoming connections.
			</description>
		</method>
		<method name="compress">
			<return type="void" />
			<argument index="0" name="mode" type="int" enum="ENetConnection.CompressionMode" />
			<description>
				Sets the compression method used for network packets. These have different tradeoffs of compression speed versus bandwidth, you may need to test which one works best for your use case if you use compression at all.
				[b]Note:[/b] Most games' network design involve sending many small packets frequently (smaller than 4 KB each). If in doubt, it is recommended to keep the default compression algorithm as it works best on these small packets.
				[b]Note:[/b] The compression mode must be set to the same value on both the server and all its clients. Clients will fail to connect if the compression mode set on the client differs from the one set on the server.
			</description>
		</method>
		<method name="connect_to_host">
			<return type="ENetPacketPeer" />
			<argument index="0" name="address" type="String" />
			<argument index="1" name="port" type="int" />
			<argument index="2" name="channels" type="int" default="0" />
			<argument index="3" name="data" type="int" default="0" />
			<description>
				Initiates a connection to a foreign [code]address[/code] using the specified [code]port[/code] and allocating the requested [code]channels[/code]. Optional [code]data[/code] can be passed during connection in the form of a 32 bit integer.
				[b]Note:[/b] You must call either [method create_host] or [method create_host_bound] before calling this method.
			</description>
		</method>
		<method name="create_host">
			<return type="int" enum="Error" />
			<argument index="0" name="max_peers" type="int" default="32" />
			<argument index="1" name="max_channels" type="int" default="0" />
			<argument index="2" name="in_bandwidth" type="int" default="0" />
			<argument index="3" name="out_bandwidth" type="int" default="0" />
			<description>
				Create an ENetHost that will allow up to [code]max_peers[/code] connected peers, each allocating up to [code]max_channels[/code] channels, optionally limiting bandwidth to [code]in_bandwidth[/code] and [code]out_bandwidth[/code].
			</description>
		</method>
		<method name="create_host_bound">
			<return type="int" enum="Error" />
			<argument index="0" name="bind_address" type="String" />
			<argument index="1" name="bind_port" type="int" />
			<argument index="2" name="max_peers" type="int" default="32" />
			<argument index="3" name="max_channels" type="int" default="0" />
			<argument index="4" name="in_bandwidth" type="int" default="0" />
			<argument index="5" name="out_bandwidth" type="int" default="0" />
			<description>
				Create an ENetHost like [method create_host] which is also bound to the given [code]bind_address[/code] and [code]bind_port[/code].
			</description>
		</method>
		<method name="destroy">
			<return type="void" />
			<description>
				Destroys the host and all resources associated with it.
			</description>
		</method>
		<method name="dtls_client_setup">
			<return type="int" enum="Error" />
			<argument index="0" name="certificate" type="X509Certificate" />
			<argument index="1" name="hostname" type="String" />
			<argument index="2" name="verify" type="bool" default="true" />
			<description>
				Configure this ENetHost to use the custom Godot extension allowing DTLS encryption for ENet clients. Call this before [method connect_to_host] to have ENet connect using DTLS with [code]certificate[/code] and [code]hostname[/code] verification. Verification can be optionally turned off via the [code]verify[/code] parameter.
			</description>
		</method>
		<method name="dtls_server_setup">
			<return type="int" enum="Error" />
			<argument index="0" name="key" type="CryptoKey" />
			<argument index="1" name="certificate" type="X509Certificate" />
			<description>
				Configure this ENetHost to use the custom Godot extension allowing DTLS encryption for ENet servers. Call this right after [method create_host_bound] to have ENet expect peers to connect using DTLS.
			</description>
		</method>
		<method name="flush">
			<return type="void" />
			<description>
				Sends any queued packets on the host specified to its designated peers.
			</description>
		</method>
		<method name="get_local_port" qualifiers="const">
			<return type="int" />
			<description>
				Returns the local port to which this peer is bound.
			</description>
		</method>
		<method name="get_max_channels" qualifiers="const">
			<return type="int" />
			<description>
				Returns the maximum number of channels allowed for connected peers.
			</description>
		</method>
		<method name="get_peers">
			<return type="Array" />
			<description>
				Returns the list of peers associated with this host.
				[b]Note:[/b] This list might include some peers that are not fully connected or are still being disconnected.
			</description>
		</method>
		<method name="pop_statistic">
			<return type="float" />
			<argument index="0" name="statistic" type="int" enum="ENetConnection.HostStatistic" />
			<description>
				Returns and resets host statistics. See [enum HostStatistic] for more info.
			</description>
		</method>
		<method name="refuse_new_connections">
			<return type="void" />
			<argument index="0" name="refuse" type="bool" />
			<description>
				Configures the DTLS server to automatically drop new connections.
				[b]Note:[/b] This method is only relevant after calling [method dtls_server_setup].
			</description>
		</method>
		<method name="service">
			<return type="Array" />
			<argument index="0" name="timeout" type="int" default="0" />
			<description>
				Waits for events on the host specified and shuttles packets between the host and its peers. The returned [Array] will have 4 elements. An [enum EventType], the [ENetPacketPeer] which generated the event, the event associated data (if any), the event associated channel (if any). If the generated event is [constant EVENT_RECEIVE], the received packet will be queued to the associated [ENetPacketPeer].
				Call this function regularly to handle connections, disconnections, and to receive new packets.
			</description>
		</method>
	</methods>
	<constants>
		<constant name="COMPRESS_NONE" value="0" enum="CompressionMode">
			No compression. This uses the most bandwidth, but has the upside of requiring the fewest CPU resources. This option may also be used to make network debugging using tools like Wireshark easier.
		</constant>
		<constant name="COMPRESS_RANGE_CODER" value="1" enum="CompressionMode">
			ENet's built-in range encoding. Works well on small packets, but is not the most efficient algorithm on packets larger than 4 KB.
		</constant>
		<constant name="COMPRESS_FASTLZ" value="2" enum="CompressionMode">
			[url=https://fastlz.org/]FastLZ[/url] compression. This option uses less CPU resources compared to [constant COMPRESS_ZLIB], at the expense of using more bandwidth.
		</constant>
		<constant name="COMPRESS_ZLIB" value="3" enum="CompressionMode">
			[url=https://www.zlib.net/]Zlib[/url] compression. This option uses less bandwidth compared to [constant COMPRESS_FASTLZ], at the expense of using more CPU resources.
		</constant>
		<constant name="COMPRESS_ZSTD" value="4" enum="CompressionMode">
			[url=https://facebook.github.io/zstd/]Zstandard[/url] compression. Note that this algorithm is not very efficient on packets smaller than 4 KB. Therefore, it's recommended to use other compression algorithms in most cases.
		</constant>
		<constant name="EVENT_ERROR" value="-1" enum="EventType">
			An error occurred during [method service]. You will likely need to [method destroy] the host and recreate it.
		</constant>
		<constant name="EVENT_NONE" value="0" enum="EventType">
			No event occurred within the specified time limit.
		</constant>
		<constant name="EVENT_CONNECT" value="1" enum="EventType">
			A connection request initiated by enet_host_connect has completed. The array will contain the peer which successfully connected.
		</constant>
		<constant name="EVENT_DISCONNECT" value="2" enum="EventType">
			A peer has disconnected. This event is generated on a successful completion of a disconnect initiated by [method ENetPacketPeer.peer_disconnect], if a peer has timed out, or if a connection request initialized by [method connect_to_host] has timed out. The array will contain the peer which disconnected. The data field contains user supplied data describing the disconnection, or 0, if none is available.
		</constant>
		<constant name="EVENT_RECEIVE" value="3" enum="EventType">
			A packet has been received from a peer. The array will contain the peer which sent the packet, the channel number upon which the packet was received, and the received packet.
		</constant>
		<constant name="HOST_TOTAL_SENT_DATA" value="0" enum="HostStatistic">
			Total data sent.
		</constant>
		<constant name="HOST_TOTAL_SENT_PACKETS" value="1" enum="HostStatistic">
			Total UDP packets sent.
		</constant>
		<constant name="HOST_TOTAL_RECEIVED_DATA" value="2" enum="HostStatistic">
			Total data received.
		</constant>
		<constant name="HOST_TOTAL_RECEIVED_PACKETS" value="3" enum="HostStatistic">
			Total UDP packets received.
		</constant>
	</constants>
</class>