Class ENetPacketPeer
A wrapper class for an ENetPeer.
- Inheritance
-
ENetPacketPeer
Remarks
A PacketPeer implementation representing a peer of an ENetConnection.
This class cannot be instantiated directly but can be retrieved during ENetConnection.service or via get_peers.
Note: When exporting to Android, make sure to enable the INTERNET
permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android.
See Also
Fields
PACKET_LOSS_SCALE
The reference scale for packet loss. See ENetPacketPeer.get_statistic and ENetPacketPeer.PEER_PACKET_LOSS.
const PACKET_LOSS_SCALE = 65536
PACKET_THROTTLE_SCALE
The reference value for throttle configuration. The default value is 32
. See ENetPacketPeer.throttle_configure.
const PACKET_THROTTLE_SCALE = 32
FLAG_RELIABLE
Mark the packet to be sent as reliable.
const FLAG_RELIABLE = 1
FLAG_UNSEQUENCED
Mark the packet to be sent unsequenced (unreliable).
const FLAG_UNSEQUENCED = 2
FLAG_UNRELIABLE_FRAGMENT
Mark the packet to be sent unreliable even if the packet is too big and needs fragmentation (increasing the chance of it being dropped).
const FLAG_UNRELIABLE_FRAGMENT = 8
Methods
get_channels
Qualifiers: const
Returns the number of channels allocated for communication with peer.
int get_channels
get_packet_flags
Qualifiers: const
Returns the ENet flags of the next packet in the received queue. See FLAG_*
constants for available packet flags. Note that not all flags are replicated from the sending peer to the receiving peer.
int get_packet_flags
get_remote_address
Qualifiers: const
Returns the IP address of this peer.
String get_remote_address
get_remote_port
Qualifiers: const
Returns the remote port of this peer.
int get_remote_port
get_state
Qualifiers: const
Returns the current peer state. See PeerState.
int get_state
get_statistic(int)
Returns the requested statistic
for this peer. See PeerStatistic.
float get_statistic(int statistic)
Parameters
statistic
int
is_active
Qualifiers: const
Returns true
if the peer is currently active (i.e. the associated ENetConnection is still valid).
bool is_active
peer_disconnect(int)
Request a disconnection from a peer. An ENetConnection.EVENT_DISCONNECT will be generated during ENetConnection.service once the disconnection is complete.
void peer_disconnect(int data)
Parameters
data
int
peer_disconnect_later(int)
Request a disconnection from a peer, but only after all queued outgoing packets are sent. An ENetConnection.EVENT_DISCONNECT will be generated during ENetConnection.service once the disconnection is complete.
void peer_disconnect_later(int data)
Parameters
data
int
peer_disconnect_now(int)
Force an immediate disconnection from a peer. No ENetConnection.EVENT_DISCONNECT will be generated. The foreign peer is not guaranteed to receive the disconnect notification, and is reset immediately upon return from this function.
void peer_disconnect_now(int data)
Parameters
data
int
ping
Sends a ping request to a peer. ENet automatically pings all connected peers at regular intervals, however, this function may be called to ensure more frequent ping requests.
void ping
ping_interval(int)
Sets the ping_interval
in milliseconds 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. The default ping interval is 500
milliseconds.
void ping_interval(int ping_interval)
Parameters
ping_interval
int
reset
Forcefully disconnects a peer. The foreign host represented by the peer is not notified of the disconnection and will timeout on its connection to the local host.
void reset
send(int, PackedByteArray, int)
Queues a packet
to be sent over the specified channel
. See FLAG_*
constants for available packet flags.
int send(int channel, PackedByteArray packet, int flags)
Parameters
channel
intpacket
PackedByteArrayflags
int
set_timeout(int, int, int)
Sets the timeout parameters for a peer. The timeout parameters control how and when a peer will timeout from a failure to acknowledge reliable traffic. Timeout values are expressed in milliseconds.
The timeout
is a factor that, multiplied by a value based on the average round trip time, will determine the timeout limit for a reliable packet. When that limit is reached, the timeout will be doubled, and the peer will be disconnected if that limit has reached timeout_min
. The timeout_max
parameter, on the other hand, defines a fixed timeout for which any packet must be acknowledged or the peer will be dropped.
void set_timeout(int timeout, int timeout_min, int timeout_max)
Parameters
throttle_configure(int, int, int)
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. By measuring fluctuations in round trip times of reliable packets over the specified interval
, ENet will either increase the probability by the amount specified in the acceleration
parameter, or decrease it by the amount specified in the deceleration
parameter (both are ratios to PACKET_THROTTLE_SCALE).
When the throttle has a value of 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.
void throttle_configure(int interval, int acceleration, int deceleration)