ENetPacketPeer
A wrapper class for an ENetPeer(http://enet.bespin.org/group__peer.html).
A wrapper class for an ENetPeer(http://enet.bespin.org/group__peer.html).
A PacketPeer implementation representing a peer of an ENetConnection.
This class cannot be instantiated directly but can be retrieved during ENetConnection.Service or via ENetConnection.GetPeers.
Note: When exporting to Android, make sure to enable the INTERNET permission in the Android export preset before exporting the project or using remote deploy. Otherwise, network communication of any kind will be blocked by Android.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Methods17
GetChannelsint
public int GetChannels();Returns the number of channels allocated for communication with peer.
intGetPacketFlagsint
public int GetPacketFlags();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.
intGetRemoteAddressstring
public string GetRemoteAddress();Returns the IP address of this peer.
stringGetRemotePortint
public int GetRemotePort();Returns the remote port of this peer.
intGetStateENetPacketPeer.PeerState
public ENetPacketPeer.PeerState GetState();Returns the current peer state.
ENetPacketPeer.PeerStateGetStatisticdouble
public double GetStatistic(ENetPacketPeer.PeerStatistic statistic);Returns the requested statistic for this peer.
| Name | Type | Default |
|---|---|---|
statistic | ENetPacketPeer.PeerStatistic | — |
doubleIsActivebool
public bool IsActive();Returns true if the peer is currently active (i.e. the associated ENetConnection is still valid).
boolPeerDisconnectvoid
public void PeerDisconnect(int data = 0);Request a disconnection from a peer. An ENetConnection.EventType.Disconnect will be generated during ENetConnection.Service once the disconnection is complete.
| Name | Type | Default |
|---|---|---|
data | int | 0 |
PeerDisconnectLatervoid
public void PeerDisconnectLater(int data = 0);Request a disconnection from a peer, but only after all queued outgoing packets are sent. An ENetConnection.EventType.Disconnect will be generated during ENetConnection.Service once the disconnection is complete.
| Name | Type | Default |
|---|---|---|
data | int | 0 |
PeerDisconnectNowvoid
public void PeerDisconnectNow(int data = 0);Force an immediate disconnection from a peer. No ENetConnection.EventType.Disconnect will be generated. The foreign peer is not guaranteed to receive the disconnect notification, and is reset immediately upon return from this function.
| Name | Type | Default |
|---|---|---|
data | int | 0 |
Pingvoid
public void 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.
PingIntervalvoid
public void PingInterval(int pingInterval);Sets the ENetPacketPeer.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.
| Name | Type | Default |
|---|---|---|
pingInterval | int | — |
Resetvoid
public void 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.
Send2 overloads
public Error Send(int channel, byte[] packet, int flags);Queues a packet to be sent over the specified channel. See FLAG_* constants for available packet flags.
| Name | Type | Default |
|---|---|---|
channel | int | — |
packet | byte[] | — |
flags | int | — |
Errorpublic Error Send(int channel, ReadOnlySpan<byte> packet, int flags);Queues a packet to be sent over the specified channel. See FLAG_* constants for available packet flags.
| Name | Type | Default |
|---|---|---|
channel | int | — |
packet | ReadOnlySpan<byte> | — |
flags | int | — |
ErrorSetTimeoutvoid
public void SetTimeout(int timeout, int timeoutMin, int timeoutMax);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.
| Name | Type | Default |
|---|---|---|
timeout | int | — |
timeoutMin | int | — |
timeoutMax | int | — |
ThrottleConfigurevoid
public void ThrottleConfigure(int interval, int acceleration, int deceleration);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 ENetPacketPeer.PacketThrottleScale).
When the throttle has a value of ENetPacketPeer.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.
| Name | Type | Default |
|---|---|---|
interval | int | — |
acceleration | int | — |
deceleration | int | — |
Fields and constants5
FlagReliableField
public const long FlagReliable = 1;Mark the packet to be sent as reliable.
FlagUnreliableFragmentField
public const long FlagUnreliableFragment = 8;Mark the packet to be sent unreliable even if the packet is too big and needs fragmentation (increasing the chance of it being dropped).
FlagUnsequencedField
public const long FlagUnsequenced = 2;Mark the packet to be sent unsequenced (unreliable).
PacketLossScaleField
public const long PacketLossScale = 65536;The reference scale for packet loss. See ENetPacketPeer.GetStatistic and ENetPacketPeer.PeerStatistic.PacketLoss.
PacketThrottleScaleField
public const long PacketThrottleScale = 32;The reference value for throttle configuration. The default value is 32. See ENetPacketPeer.ThrottleConfigure.
ENetPacketPeer.PeerState
| Value | Description |
|---|---|
AcknowledgingConnect = 2 | The peer has acknowledged the connection request. |
AcknowledgingDisconnect = 8 | The peer has acknowledged the disconnection request. |
Connected = 5 | The peer is currently connected and ready to communicate with. |
Connecting = 1 | The peer is currently attempting to connect. |
ConnectionPending = 3 | The peer is currently connecting. |
ConnectionSucceeded = 4 | The peer has successfully connected, but is not ready to communicate with yet ( |
DisconnectLater = 6 | The peer is expected to disconnect after it has no more outgoing packets to send. |
Disconnected = 0 | The peer is disconnected. |
Disconnecting = 7 | The peer is currently disconnecting. |
Zombie = 9 | The peer has lost connection, but is not considered truly disconnected (as the peer didn't acknowledge the disconnection request). |
ENetPacketPeer.PeerStatistic
| Value | Description |
|---|---|
LastRoundTripTime = 5 | Last recorded round trip time for a reliable packet. |
LastRoundTripTimeVariance = 6 | Variance of the last trip time recorded. |
PacketLoss = 0 | Mean packet loss of reliable packets as a ratio with respect to the |
PacketLossEpoch = 2 | The time at which packet loss statistics were last updated (in milliseconds since the connection started). The interval for packet loss statistics updates is 10 seconds, and at least one packet must have been sent since the last statistics update. |
PacketLossVariance = 1 | Packet loss variance. |
PacketThrottle = 7 | The peer's current throttle status. |
PacketThrottleAcceleration = 11 | The throttle's acceleration factor. Higher values will make ENet adapt to fluctuating network conditions faster, causing unrelaible packets to be sent more often. The default value is |
PacketThrottleCounter = 9 | Internal value used to increment the packet throttle counter. The value is hardcoded to |
PacketThrottleDeceleration = 12 | The throttle's deceleration factor. Higher values will make ENet adapt to fluctuating network conditions faster, causing unrelaible packets to be sent less often. The default value is |
PacketThrottleEpoch = 10 | The time at which throttle statistics were last updated (in milliseconds since the connection started). The interval for throttle statistics updates is |
PacketThrottleInterval = 13 | The interval over which the lowest mean round trip time should be measured for use by the throttle mechanism (in milliseconds). The default value is |
PacketThrottleLimit = 8 | The maximum number of unreliable packets that should not be dropped. This value is always greater than or equal to |
RoundTripTime = 3 | Mean packet round trip time for reliable packets. |
RoundTripTimeVariance = 4 | Variance of the mean round trip time. |