Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

ENetConnection

Inherits: RefCounted < Object

A wrapper class for an ENetHost.

Description

ENet's purpose is to provide a relatively thin, simple and robust network communication layer on top of UDP (User Datagram Protocol).

Tutorials

Methods

void

bandwidth_limit(in_bandwidth: int = 0, out_bandwidth: int = 0)

void

broadcast(channel: int, packet: PackedByteArray, flags: int)

void

channel_limit(limit: int)

void

compress(mode: CompressionMode)

ENetPacketPeer

connect_to_host(address: String, port: int, channels: int = 0, data: int = 0)

Error

create_host(max_peers: int = 32, max_channels: int = 0, in_bandwidth: int = 0, out_bandwidth: int = 0)

Error

create_host_bound(bind_address: String, bind_port: int, max_peers: int = 32, max_channels: int = 0, in_bandwidth: int = 0, out_bandwidth: int = 0)

void

destroy()

Error

dtls_client_setup(hostname: String, client_options: TLSOptions = null)

Error

dtls_server_setup(server_options: TLSOptions)

void

flush()

int

get_local_port() const

int

get_max_channels() const

Array[ENetPacketPeer]

get_peers()

float

pop_statistic(statistic: HostStatistic)

void

refuse_new_connections(refuse: bool)

Array

service(timeout: int = 0)

void

socket_send(destination_address: String, destination_port: int, packet: PackedByteArray)


Enumerations

enum CompressionMode:

CompressionMode COMPRESS_NONE = 0

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.

CompressionMode COMPRESS_RANGE_CODER = 1

ENet's built-in range encoding. Works well on small packets, but is not the most efficient algorithm on packets larger than 4 KB.

CompressionMode COMPRESS_FASTLZ = 2

FastLZ compression. This option uses less CPU resources compared to COMPRESS_ZLIB, at the expense of using more bandwidth.

CompressionMode COMPRESS_ZLIB = 3

Zlib compression. This option uses less bandwidth compared to COMPRESS_FASTLZ, at the expense of using more CPU resources.

CompressionMode COMPRESS_ZSTD = 4

Zstandard 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.


enum EventType:

EventType EVENT_ERROR = -1

An error occurred during service. You will likely need to destroy the host and recreate it.

EventType EVENT_NONE = 0

No event occurred within the specified time limit.

EventType EVENT_CONNECT = 1

A connection request initiated by enet_host_connect has completed. The array will contain the peer which successfully connected.

EventType EVENT_DISCONNECT = 2

A peer has disconnected. This event is generated on a successful completion of a disconnect initiated by ENetPacketPeer.peer_disconnect, if a peer has timed out, or if a connection request initialized by 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.

EventType EVENT_RECEIVE = 3

A packet has been received from a peer. The array will contain the peer which sent the packet and the channel number upon which the packet was received. The received packet will be queued to the associated ENetPacketPeer.


enum HostStatistic:

HostStatistic HOST_TOTAL_SENT_DATA = 0

Total data sent.