<?xml version="1.0" encoding="UTF-8" ?>
<class name="ENetConnection" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
	<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" />
			<param index="0" name="in_bandwidth" type="int" default="0" />
			<param 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" />
			<param index="0" name="channel" type="int" />
			<param index="1" name="packet" type="PackedByteArray" />
			<param 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" />
			<param index="0" name="limit" type="int" />
			<description>
				Limits the maximum allowed channels of future incoming connections.
			</description>
		</method>
		<method name="compress">
			<return type="void" />
			<param 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" />
			<param index="0" name="address" type="String" />
			<param index="1" name="port" type="int" />
			<param index="2" name="channels" type="int" default="0" />
			<param 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" />
			<param index="0" name="max_peers" type="int" default="32" />
			<param index="1" name="max_channels" type="int" default="0" />
			<param index="2" name="in_bandwidth" type="int" default="0" />
			<param 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" />
			<param index="0" name="bind_address" type="String" />
			<param index="1" name="bind_port" type="int" />
			<param index="2" name="max_peers" type="int" default="32" />
			<param index="3" name="max_channels" type="int" default="0" />
			<param index="4" name="in_bandwidth" type="int" default="0" />
			<param 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" />
			<param index="0" name="certificate" type="X509Certificate" />
			<param index="1" name="hostname" type="String" />
			<param 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" />
			<param index="0" name="key" type="CryptoKey" />
			<param 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" />
			<param 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" />
			<param 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" />
			<param 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>
