EnetHost

from acron.enet import EnetHost
class EnetHost

Bases:

Bases: ReferenceCount

A local communication endpoint using the ENet reliable-UDP protocol, in either server or client role. Wraps ENetHost.

Create one with create_server() or create_client(), then pump it by calling service() regularly (e.g. from a task); service() returns the next pending EnetEvent, or None if nothing happened within the timeout.

A host (together with its peers) should be pumped and used from a single thread, as with the underlying ENet library. A per-host lock guards the internal peer bookkeeping so that concurrent calls do not corrupt it, but note that service() holds that lock for the duration of its blocking wait: calling other methods on the host from a second thread while service() is waiting on a non-zero timeout will block until it returns. Prefer a timeout of 0 and a regular poll if you need to touch the host elsewhere.

Inheritance diagram

digraph inheritance2b13a91192 { bgcolor=transparent; rankdir=BT; size="8.0, 12.0"; "DTOOL_SUPER_BASE" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style=""]; "EnetHost" [URL="acron.enet.EnetHost.html#acron.enet.EnetHost",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "ReferenceCount" -> "EnetHost" [arrowsize=0.75,style=""]; "ReferenceCount" [URL="acron.core.ReferenceCount.html#acron.core.ReferenceCount",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "ReferenceCount" [arrowsize=0.75,style=""]; }
property address → EnetAddress

Returns the local address this host is bound to. For servers this includes the listen port; for clients the port is assigned by the OS on first use.

broadcast()

Queues a packet to be sent to every connected peer on this host.

broadcast_datagram()

Queues the contents of the given datagram to be sent to every connected peer on this host.

compress_with_range_coder()

Enables ENet’s built-in range-coder compression for this host’s traffic. Both ends of a connection must agree on this.

Enables ENet’s built-in range-coder compression for this host’s traffic. Both ends of a connection must enable this. Returns true on success.

connect()

Initiates a connection to a remote host (dotted-quad IP string or DNS name) and port. Returns the new peer, or None if the attempt could not be started. The connection is not established until a T_connect event for this peer arrives via service().

The optional data value is delivered to the remote end in its T_connect event.

static create_client()

Creates a client host, not bound to a specific port, able to make up to peer_count outgoing connections (usually 1) with channel_limit channels each. Bandwidth limits are in bytes/second, 0 meaning unlimited.

static create_server()

Creates a server host bound to the given UDP port, able to accept up to peer_count simultaneous connections with channel_limit channels each. Bandwidth limits are in bytes/second, 0 meaning unlimited. By default the host binds all interfaces; pass a bind_address to bind a specific one. Returns None on failure (e.g. the port is already in use).

flush()

Sends any queued packets immediately, without receiving or dispatching events.

get_address()

Returns the local address this host is bound to. For servers this includes the listen port; for clients the port is assigned by the OS on first use.

get_peer_count()

Returns the number of currently connected peers.

get_total_received_data()

Returns the total number of bytes received since creation or reset_totals().

get_total_received_packets()

Returns the total number of UDP packets received since creation or reset_totals().

get_total_sent_data()

Returns the total number of bytes sent since creation or reset_totals().

get_total_sent_packets()

Returns the total number of UDP packets sent since creation or reset_totals().

output()
property peer_count → int

Returns the number of currently connected peers.

reset_totals()

Resets the total sent/received counters to zero.

service()

Sends queued packets, receives incoming ones, and returns the next pending event, waiting up to timeout_ms milliseconds for something to happen. Returns None if no event occurred. Call this regularly (e.g. every frame with the default timeout of 0), repeating until it returns None to drain all pending events.

set_channel_limit()

Adjusts the maximum number of channels allowed for future incoming connections.