EnetPeer

class EnetPeer

Bases: ReferenceCount

Represents a single remote endpoint of an EnetHost connection. Peer objects are created by EnetHost (via connect() or incoming connection events); the same EnetPeer instance is returned for every event involving the same underlying connection, so it can be used as a stable identity.

After the connection goes away (disconnect event, host destroyed), the peer becomes invalid: is_valid() returns false and all operations turn into no-ops.

Inheritance diagram

digraph inheritance14a1d91251 { 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=""]; "EnetPeer" [URL="acron.enet.EnetPeer.html#acron.enet.EnetPeer",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "ReferenceCount" -> "EnetPeer" [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=""]; }
enum PacketFlag

Mirrors ENET_PACKET_FLAG_*.

enumerator PF_unreliable = 0
enumerator PF_reliable = 1
enumerator PF_unsequenced = 2
enumerator PF_unreliable_fragment = 8
enum State

Mirrors ENET_PEER_STATE_*.

enumerator S_disconnected = 0
enumerator S_connecting = 1
enumerator S_acknowledging_connect = 2
enumerator S_connection_pending = 3
enumerator S_connection_succeeded = 4
enumerator S_connected = 5
enumerator S_disconnect_later = 6
enumerator S_disconnecting = 7
enumerator S_acknowledging_disconnect = 8
enumerator S_zombie = 9
EnetPeer.disconnect()

Requests a graceful disconnection. Queued outgoing packets are sent first; once the disconnection completes, a T_disconnect event is generated on the host.

EnetPeer.disconnect_later()

Like disconnect(), but delivers all queued packets (in both directions) before disconnecting.

EnetPeer.disconnect_now()

Sends a disconnect notification and immediately resets the connection. The remote end may or may not see the notification. No T_disconnect event is generated locally; this peer becomes invalid immediately.

EnetPeer.get_address()

Returns the remote address of the peer.

EnetPeer.get_channel_count()

Returns the number of channels allocated for this connection.

EnetPeer.get_connect_id()

Returns a number that uniquely identifies this connection attempt, as negotiated during the ENet handshake. Both ends see the same value.

EnetPeer.get_packet_loss()

Returns the mean packet loss of reliable packets, as a ratio out of 65536 (ENET_PEER_PACKET_LOSS_SCALE).

EnetPeer.get_round_trip_time()

Returns the mean round trip time to the peer, in milliseconds.

EnetPeer.get_state()

Returns the current connection state.

EnetPeer.is_connected()

Returns true if the connection is fully established.

EnetPeer.is_valid()

Returns true as long as this peer refers to a live ENet connection slot. A peer becomes invalid after a T_disconnect event, after disconnect_now() or reset(), or when its host is destroyed.

EnetPeer.output()
EnetPeer.ping()

Sends a ping request to the peer. Pings also happen automatically at the configured ping interval.

EnetPeer.reset()

Forcefully resets the connection without notifying the remote end. No T_disconnect event is generated locally; this peer becomes invalid immediately.

EnetPeer.send()

Queues a packet with the given payload to be sent on the given channel. The default flags make the packet reliable; pass PF_unreliable (0) for fire-and-forget delivery, or PF_unsequenced for unordered delivery. Returns true if the packet was queued successfully. The packet goes out on the next service() or flush() call on the host.

EnetPeer.send_datagram()

Sends the contents of the given datagram; see send().

EnetPeer.set_ping_interval()

Sets the interval, in milliseconds, at which pings are sent to keep the connection (and its round-trip-time measurement) fresh.

EnetPeer.set_timeout()

Configures the timeout after which an unresponsive peer is disconnected. timeout_limit is a multiplier on the retry timeout (0 for the default); the connection is dropped no sooner than timeout_minimum_ms and no later than timeout_maximum_ms of unacknowledged traffic.

EnetPeer.throttle_configure()

Configures the packet throttle for this peer; see the ENet documentation for enet_peer_throttle_configure().