ENet  v1.3.17
Reliable UDP networking library
Functions
ENet peer functions

Functions

void enet_peer_disconnect (ENetPeer *peer, enet_uint32 data)
 Request a disconnection from a peer. More...
 
void enet_peer_disconnect_later (ENetPeer *peer, enet_uint32 data)
 Request a disconnection from a peer, but only after all queued outgoing packets are sent. More...
 
void enet_peer_disconnect_now (ENetPeer *peer, enet_uint32 data)
 Force an immediate disconnection from a peer. More...
 
void enet_peer_dispatch_incoming_reliable_commands (ENetPeer *peer, ENetChannel *channel, ENetIncomingCommand *queuedCommand)
 
void enet_peer_dispatch_incoming_unreliable_commands (ENetPeer *peer, ENetChannel *channel, ENetIncomingCommand *queuedCommand)
 
void enet_peer_on_connect (ENetPeer *peer)
 
void enet_peer_on_disconnect (ENetPeer *peer)
 
void enet_peer_ping (ENetPeer *peer)
 Sends a ping request to a peer. More...
 
void enet_peer_ping_interval (ENetPeer *peer, enet_uint32 pingInterval)
 Sets the interval at which pings will be sent to a peer. More...
 
ENetAcknowledgementenet_peer_queue_acknowledgement (ENetPeer *peer, const ENetProtocol *command, enet_uint16 sentTime)
 
ENetIncomingCommandenet_peer_queue_incoming_command (ENetPeer *peer, const ENetProtocol *command, const void *data, size_t dataLength, enet_uint32 flags, enet_uint32 fragmentCount)
 
ENetOutgoingCommandenet_peer_queue_outgoing_command (ENetPeer *peer, const ENetProtocol *command, ENetPacket *packet, enet_uint32 offset, enet_uint16 length)
 
ENetPacketenet_peer_receive (ENetPeer *peer, enet_uint8 *channelID)
 Attempts to dequeue any incoming queued packet. More...
 
void enet_peer_reset (ENetPeer *peer)
 Forcefully disconnects a peer. More...
 
void enet_peer_reset_queues (ENetPeer *peer)
 
int enet_peer_send (ENetPeer *peer, enet_uint8 channelID, ENetPacket *packet)
 Queues a packet to be sent. More...
 
void enet_peer_setup_outgoing_command (ENetPeer *peer, ENetOutgoingCommand *outgoingCommand)
 
int enet_peer_throttle (ENetPeer *peer, enet_uint32 rtt)
 
void enet_peer_throttle_configure (ENetPeer *peer, enet_uint32 interval, enet_uint32 acceleration, enet_uint32 deceleration)
 Configures throttle parameter for a peer. More...
 
void enet_peer_timeout (ENetPeer *peer, enet_uint32 timeoutLimit, enet_uint32 timeoutMinimum, enet_uint32 timeoutMaximum)
 Sets the timeout parameters for a peer. More...
 

Detailed Description

Function Documentation

◆ enet_peer_disconnect()

void enet_peer_disconnect ( ENetPeer peer,
enet_uint32  data 
)

#include <peer.c>

Request a disconnection from a peer.

Parameters
peerpeer to request a disconnection
datadata describing the disconnection
Remarks
An ENET_EVENT_DISCONNECT event will be generated by enet_host_service() once the disconnection is complete.

◆ enet_peer_disconnect_later()

void enet_peer_disconnect_later ( ENetPeer peer,
enet_uint32  data 
)

#include <peer.c>

Request a disconnection from a peer, but only after all queued outgoing packets are sent.

Parameters
peerpeer to request a disconnection
datadata describing the disconnection
Remarks
An ENET_EVENT_DISCONNECT event will be generated by enet_host_service() once the disconnection is complete.

◆ enet_peer_disconnect_now()

void enet_peer_disconnect_now ( ENetPeer peer,
enet_uint32  data 
)

#include <peer.c>

Force an immediate disconnection from a peer.

Parameters
peerpeer to disconnect
datadata describing the disconnection
Remarks
No ENET_EVENT_DISCONNECT event will be generated. The foreign peer is not guaranteed to receive the disconnect notification, and is reset immediately upon return from this function.

◆ enet_peer_dispatch_incoming_reliable_commands()

void enet_peer_dispatch_incoming_reliable_commands ( ENetPeer peer,
ENetChannel channel,
ENetIncomingCommand queuedCommand 
)

#include <peer.c>

◆ enet_peer_dispatch_incoming_unreliable_commands()

void enet_peer_dispatch_incoming_unreliable_commands ( ENetPeer peer,
ENetChannel channel,
ENetIncomingCommand queuedCommand 
)

#include <peer.c>

◆ enet_peer_on_connect()

void enet_peer_on_connect ( ENetPeer peer)

#include <peer.c>

◆ enet_peer_on_disconnect()

void enet_peer_on_disconnect ( ENetPeer peer)

#include <peer.c>

◆ enet_peer_ping()

void enet_peer_ping ( ENetPeer peer)

#include <peer.c>

Sends a ping request to a peer.

Parameters
peerdestination for the ping request
Remarks
ping requests factor into the mean round trip time as designated by the roundTripTime field in the ENetPeer structure. ENet automatically pings all connected peers at regular intervals, however, this function may be called to ensure more frequent ping requests.

◆ enet_peer_ping_interval()

void enet_peer_ping_interval ( ENetPeer peer,
enet_uint32  pingInterval 
)

#include <peer.c>

Sets the interval at which pings will be sent to a peer.

Pings are used both to monitor the liveness of the connection and also to dynamically adjust the throttle during periods of low traffic so that the throttle has reasonable responsiveness during traffic spikes.

Parameters
peerthe peer to adjust
pingIntervalthe interval at which to send pings; defaults to ENET_PEER_PING_INTERVAL if 0

◆ enet_peer_queue_acknowledgement()

ENetAcknowledgement* enet_peer_queue_acknowledgement ( ENetPeer peer,
const ENetProtocol command,
enet_uint16  sentTime 
)

#include <peer.c>

◆ enet_peer_queue_incoming_command()

ENetIncomingCommand* enet_peer_queue_incoming_command ( ENetPeer peer,
const ENetProtocol command,
const void *  data,
size_t  dataLength,
enet_uint32  flags,
enet_uint32  fragmentCount 
)

#include <peer.c>

◆ enet_peer_queue_outgoing_command()

ENetOutgoingCommand* enet_peer_queue_outgoing_command ( ENetPeer peer,
const ENetProtocol command,
ENetPacket packet,
enet_uint32  offset,
enet_uint16  length 
)

#include <peer.c>

◆ enet_peer_receive()

ENetPacket* enet_peer_receive ( ENetPeer peer,
enet_uint8 channelID 
)

#include <peer.c>

Attempts to dequeue any incoming queued packet.

Parameters
peerpeer to dequeue packets from
channelIDholds the channel ID of the channel the packet was received on success
Returns
a pointer to the packet, or NULL if there are no available incoming queued packets

◆ enet_peer_reset()

void enet_peer_reset ( ENetPeer peer)

#include <peer.c>

Forcefully disconnects a peer.

Parameters
peerpeer to forcefully disconnect
Remarks
The foreign host represented by the peer is not notified of the disconnection and will timeout on its connection to the local host.

◆ enet_peer_reset_queues()

void enet_peer_reset_queues ( ENetPeer peer)

#include <peer.c>

◆ enet_peer_send()

int enet_peer_send ( ENetPeer peer,
enet_uint8  channelID,
ENetPacket packet 
)

#include <peer.c>

Queues a packet to be sent.

Parameters
peerdestination for the packet
channelIDchannel on which to send
packetpacket to send
Return values
0on success
<0 on failure

◆ enet_peer_setup_outgoing_command()

void enet_peer_setup_outgoing_command ( ENetPeer peer,
ENetOutgoingCommand outgoingCommand 
)

#include <peer.c>

◆ enet_peer_throttle()

int enet_peer_throttle ( ENetPeer peer,
enet_uint32  rtt 
)

#include <peer.c>

◆ enet_peer_throttle_configure()

void enet_peer_throttle_configure ( ENetPeer peer,
enet_uint32  interval,
enet_uint32  acceleration,
enet_uint32  deceleration 
)

#include <peer.c>

Configures throttle parameter for a peer.

Unreliable packets are dropped by ENet in response to the varying conditions of the Internet connection to the peer. The throttle represents a probability that an unreliable packet should not be dropped and thus sent by ENet to the peer. The lowest mean round trip time from the sending of a reliable packet to the receipt of its acknowledgement is measured over an amount of time specified by the interval parameter in milliseconds. If a measured round trip time happens to be significantly less than the mean round trip time measured over the interval, then the throttle probability is increased to allow more traffic by an amount specified in the acceleration parameter, which is a ratio to the ENET_PEER_PACKET_THROTTLE_SCALE constant. If a measured round trip time happens to be significantly greater than the mean round trip time measured over the interval, then the throttle probability is decreased to limit traffic by an amount specified in the deceleration parameter, which is a ratio to the ENET_PEER_PACKET_THROTTLE_SCALE constant. When the throttle has a value of ENET_PEER_PACKET_THROTTLE_SCALE, no unreliable packets are dropped by ENet, and so 100% of all unreliable packets will be sent. When the throttle has a value of 0, all unreliable packets are dropped by ENet, and so 0% of all unreliable packets will be sent. Intermediate values for the throttle represent intermediate probabilities between 0% and 100% of unreliable packets being sent. The bandwidth limits of the local and foreign hosts are taken into account to determine a sensible limit for the throttle probability above which it should not raise even in the best of conditions.

Parameters
peerpeer to configure
intervalinterval, in milliseconds, over which to measure lowest mean RTT; the default value is ENET_PEER_PACKET_THROTTLE_INTERVAL.
accelerationrate at which to increase the throttle probability as mean RTT declines
decelerationrate at which to decrease the throttle probability as mean RTT increases

◆ enet_peer_timeout()

void enet_peer_timeout ( ENetPeer peer,
enet_uint32  timeoutLimit,
enet_uint32  timeoutMinimum,
enet_uint32  timeoutMaximum 
)

#include <peer.c>

Sets the timeout parameters for a peer.

The timeout parameter control how and when a peer will timeout from a failure to acknowledge reliable traffic. Timeout values use an exponential backoff mechanism, where if a reliable packet is not acknowledge within some multiple of the average RTT plus a variance tolerance, the timeout will be doubled until it reaches a set limit. If the timeout is thus at this limit and reliable packets have been sent but not acknowledged within a certain minimum time period, the peer will be disconnected. Alternatively, if reliable packets have been sent but not acknowledged for a certain maximum time period, the peer will be disconnected regardless of the current timeout limit value.

Parameters
peerthe peer to adjust
timeoutLimitthe timeout limit; defaults to ENET_PEER_TIMEOUT_LIMIT if 0
timeoutMinimumthe timeout minimum; defaults to ENET_PEER_TIMEOUT_MINIMUM if 0
timeoutMaximumthe timeout maximum; defaults to ENET_PEER_TIMEOUT_MAXIMUM if 0