Class ENetPacketPeer
- Namespace
- Godot
- Assembly
- GodotSharp.dll
A PacketPeer implementation representing a peer of an ENetConnection.
This class cannot be instantiated directly but can be retrieved during Service(int) or via GetPeers().
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.
public class ENetPacketPeer : PacketPeer, IDisposable
- Inheritance
-
ENetPacketPeer
- Implements
- Inherited Members
Fields
FlagReliable
Mark the packet to be sent as reliable.
public const long FlagReliable = 1
Field Value
FlagUnreliableFragment
Mark the packet to be sent unreliable even if the packet is too big and needs fragmentation (increasing the chance of it being dropped).
public const long FlagUnreliableFragment = 8
Field Value
FlagUnsequenced
Mark the packet to be sent unsequenced (unreliable).
public const long FlagUnsequenced = 2
Field Value
PacketLossScale
The reference scale for packet loss. See GetStatistic(PeerStatistic) and PacketLoss.
public const long PacketLossScale = 65536
Field Value
PacketThrottleScale
The reference value for throttle configuration. The default value is 32
. See ThrottleConfigure(int, int, int).
public const long PacketThrottleScale = 32
Field Value
Methods
GetChannels()
Returns the number of channels allocated for communication with peer.
public int GetChannels()
Returns
GetRemoteAddress()
Returns the IP address of this peer.
public string GetRemoteAddress()
Returns
GetRemotePort()
Returns the remote port of this peer.
public int GetRemotePort()
Returns
GetState()
Returns the current peer state. See ENetPacketPeer.PeerState.
public ENetPacketPeer.PeerState GetState()
Returns
GetStatistic(PeerStatistic)
Returns the requested statistic
for this peer. See ENetPacketPeer.PeerStatistic.
public double GetStatistic(ENetPacketPeer.PeerStatistic statistic)
Parameters
statistic
ENetPacketPeer.PeerStatistic
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
IsActive()
Returns true
if the peer is currently active (i.e. the associated ENetConnection is still valid).
public bool IsActive()
Returns
PeerDisconnect(int)
Request a disconnection from a peer. An Disconnect will be generated during Service(int) once the disconnection is complete.
public void PeerDisconnect(int data = 0)
Parameters
data
int
PeerDisconnectLater(int)
Request a disconnection from a peer, but only after all queued outgoing packets are sent. An Disconnect will be generated during Service(int) once the disconnection is complete.
public void PeerDisconnectLater(int data = 0)
Parameters
data
int
PeerDisconnectNow(int)
Force an immediate disconnection from a peer. No Disconnect will be generated. The foreign peer is not guaranteed to receive the disconnect notification, and is reset immediately upon return from this function.
public void PeerDisconnectNow(int data = 0)
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.
public void Ping()
PingInterval(int)
Sets the pingInterval
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.
public void PingInterval(int pingInterval)
Parameters
pingInterval
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.
public void Reset()
Send(int, byte[], int)
Queues a packet
to be sent over the specified channel
. See FLAG_*
constants for available packet flags.
public Error Send(int channel, byte[] packet, int flags)
Parameters
Returns
SetTimeout(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 timeoutMin
. The timeoutMax
parameter, on the other hand, defines a fixed timeout for which any packet must be acknowledged or the peer will be dropped.
public void SetTimeout(int timeout, int timeoutMin, int timeoutMax)
Parameters
ThrottleConfigure(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 PacketThrottleScale).
When the throttle has a value of PacketThrottleScale, 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.
public void ThrottleConfigure(int interval, int acceleration, int deceleration)