ENet Networking

ENet is a networking library built for games: it runs over UDP, so latency stays low, and adds what a game needs on top – connections, optional reliable and ordered delivery per packet, several channels per connection, fragmentation of large packets, bandwidth throttling and packet-loss statistics. The acron.enet module wraps it for use from Python and C++ and integrates it with the engine’s Datagram classes. ENet itself (version 1.3.18) is compiled into the module; there is nothing to install.

Compared with the datagram protocol classes, which give you a TCP stream or raw UDP, ENet gives a session: a client connects to a server, both sides learn about connections and disconnections as events, and each message is sent on a channel with the delivery guarantee you choose. For a multiplayer game with a server and a handful of clients it is usually the right level.

The classes

EnetHost

One end of the network: a server bound to a port, or a client. A host accepts connections, makes them, and produces the events. It is created with create_server() or create_client().

EnetPeer

A connection to another host. Messages are sent to a peer; a peer is disconnected, pinged, and measured.

EnetEvent

What EnetHost.service() returns: a connection, a disconnection or a received packet, with the peer it concerns and the payload.

EnetAddress

A host name or IP address and a port.

The module is built when makeacron is given --use-enet. Its tests, under tests/enet, run a server and clients in one process and are a compact reference for every call.