Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

ENetPacketPeer

Hérite de : PacketPeer < RefCounted < Object

Une classe wrapper pour un ENetPeer.

Description

Une implémentation de PacketPeer représentant un pair d'une ENetConnection.

Cette classe ne peut pas être instanciée directement mais peut être récupérée pendant ENetConnection.service() ou via ENetConnection.get_peers().

Note : Lors de l'export vers Android, assurez-vous d'activer la permission INTERNET dans le préréglage d'export Android avant d'exporter le projet ou en utilisant le déploiement en un clic. Sinon, la communication réseau de tout type sera bloquée par Android.

Tutoriels

Méthodes

int

get_channels() const

int

get_packet_flags() const

String

get_remote_address() const

int

get_remote_port() const

PeerState

get_state() const

float

get_statistic(statistic: PeerStatistic)

bool

is_active() const

void

peer_disconnect(data: int = 0)

void

peer_disconnect_later(data: int = 0)

void

peer_disconnect_now(data: int = 0)

void

ping()

void

ping_interval(ping_interval: int)

void

reset()

Error

send(channel: int, packet: PackedByteArray, flags: int)

void

set_timeout(timeout: int, timeout_min: int, timeout_max: int)

void

throttle_configure(interval: int, acceleration: int, deceleration: int)


Énumérations

enum PeerState: 🔗

PeerState STATE_DISCONNECTED = 0

Le pair est déconnecté.

PeerState STATE_CONNECTING = 1

Le pair est en train d'essayer de se connecter.

PeerState STATE_ACKNOWLEDGING_CONNECT = 2

The peer has acknowledged the connection request.

PeerState STATE_CONNECTION_PENDING = 3

Le pair est actuellement en train de se connecter.

PeerState STATE_CONNECTION_SUCCEEDED = 4

Le pair a réussi à se connecter, mais n'est pas prêt à être communiqué avec (STATE_CONNECTED).

PeerState STATE_CONNECTED = 5

Le pair est actuellement connecté et prêt à être communiqué avec.

PeerState STATE_DISCONNECT_LATER = 6

Le pair devrait se déconnecter après qu'il n'ait plus de paquets sortants à envoyer.

PeerState STATE_DISCONNECTING = 7

Le pair est en cours de déconnexion.

PeerState STATE_ACKNOWLEDGING_DISCONNECT = 8

Le pair a reconnu la demande de déconnexion.

PeerState STATE_ZOMBIE = 9

Le pair a perdu la connexion, mais n'est pas considéré comme vraiment déconnecté (car le pair n'a pas reconnu la demande de déconnexion).


enum PeerStatistic: 🔗

PeerStatistic PEER_PACKET_LOSS = 0

Mean packet loss of reliable packets as a ratio with respect to the PACKET_LOSS_SCALE.

PeerStatistic PEER_PACKET_LOSS_VARIANCE = 1

Variance de paquets perdus.

PeerStatistic PEER_PACKET_LOSS_EPOCH = 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.

PeerStatistic PEER_ROUND_TRIP_TIME = 3

Mean packet round trip time for reliable packets.

PeerStatistic PEER_ROUND_TRIP_TIME_VARIANCE = 4

Variance of the mean round trip time.

PeerStatistic PEER_LAST_ROUND_TRIP_TIME = 5

Last recorded round trip time for a reliable packet.

PeerStatistic PEER_LAST_ROUND_TRIP_TIME_VARIANCE = 6

Variance of the last trip time recorded.

PeerStatistic PEER_PACKET_THROTTLE = 7

The peer's current throttle status.

PeerStatistic PEER_PACKET_THROTTLE_LIMIT = 8

The maximum number of unreliable packets that should not be dropped. This value is always greater than or equal to 1. The initial value is equal to PACKET_THROTTLE_SCALE.

PeerStatistic PEER_PACKET_THROTTLE_COUNTER = 9

Internal value used to increment the packet throttle counter. The value is hardcoded to 7 and cannot be changed. You probably want to look at PEER_PACKET_THROTTLE_ACCELERATION instead.

PeerStatistic PEER_PACKET_THROTTLE_EPOCH = 10

The time at which throttle statistics were last updated (in milliseconds since the connection started). The interval for throttle statistics updates is PEER_PACKET_THROTTLE_INTERVAL.

PeerStatistic PEER_PACKET_THROTTLE_ACCELERATION = 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 2.

PeerStatistic PEER_PACKET_THROTTLE_DECELERATION = 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 2.

PeerStatistic PEER_PACKET_THROTTLE_INTERVAL = 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 5000.


Constantes

PACKET_LOSS_SCALE = 65536 🔗

The reference scale for packet loss. See get_statistic() and PEER_PACKET_LOSS.

PACKET_THROTTLE_SCALE = 32 🔗

The reference value for throttle configuration. The default value is 32. See throttle_configure().

FLAG_RELIABLE = 1 🔗

Mark the packet to be sent as reliable.

FLAG_UNSEQUENCED = 2 🔗

Mark the packet to be sent unsequenced (unreliable).

FLAG_UNRELIABLE_FRAGMENT = 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).


Descriptions des méthodes

int get_channels() const 🔗

Renvoie le nombre de canaux alloués à la communication avec le pair.


int get_packet_flags() const 🔗

Renvoie les drapeaux ENet du prochain paquet dans la file reçue. Voir les constantes FLAG_* pour les drapeaux de paquet disponibles. Notez que les drapeaux ne sont pas tous répliqués entre le pair émetteur et le pair récepteur.


String get_remote_address() const 🔗

Renvoie l'adresse IP de ce pair.


int get_remote_port() const 🔗

Renvoie le port distant de ce pair.


PeerState get_state() const 🔗

Renvoie l'état actuel du pair.


float get_statistic(statistic: PeerStatistic) 🔗

Renvoie la statistique statistic demandée pour ce pair.


bool is_active() const 🔗

Renvoie true si le pair est actuellement actif (c.-à-d. que le ENetConnection associé est toujours valide).


void peer_disconnect(data: int = 0) 🔗

Demande une déconnexion d'un pair. Un évènement ENetConnection.EVENT_DISCONNECT sera généré pendant ENetConnection.service() une fois la déconnexion terminée.


void peer_disconnect_later(data: int = 0) 🔗

Demande une déconnexion d'un pair, mais seulement après que tous les paquets en cours d'attente soient envoyés. Un évènement ENetConnection.EVENT_DISCONNECT sera généré pendant ENetConnection.service() une fois la déconnexion terminée.


void peer_disconnect_now(data: int = 0) 🔗

Force une déconnexion immédiate d'un pair. Aucun évènement ENetConnection.EVENT_DISCONNECT ne sera généré. Le pair étranger n'est pas garanti de recevoir la notification de déconnexion et est réinitialisé immédiatement après le renvoi de cette fonction.


void ping() 🔗

Envoye une requête de ping à un pair. ENet ping automatiquement tous les pairs connectés à intervalles réguliers, cependant, cette fonction peut être appelée pour assurer des requêtes de ping plus fréquentes.


void ping_interval(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 reset() 🔗

Force la déconnexion d'un pair. L'hôte étranger représenté par le pair n'est pas averti de la déconnexion et fera un timeout sur sa connexion à l'hôte local.


Error send(channel: int, packet: PackedByteArray, flags: int) 🔗

Queues a packet to be sent over the specified channel. See FLAG_* constants for available packet flags.


void set_timeout(timeout: int, timeout_min: int, timeout_max: int) 🔗

Définit les paramètres de limite de temps pour un pair. Les paramètres de limite de temps contrôlent comment et quand un pair estimera que le trafic n'est pas assez fiable. Les valeurs de limite de temps sont exprimées en millisecondes.

Letimeout est un facteur qui, multiplié par une valeur basée sur le temps d'envoi moyen, déterminera la limite de temps pour un paquet fiable. Lorsque cette limite est atteinte, la limite de temps sera doublée, et le pair sera déconnecté si cette limite atteint timeout_min. Le paramètre timeout_max , d'autre part, définit une limite de temps fixe pour lequel tout paquet doit estimé comme fiable, ou alors le pair sera supprimé.


void throttle_configure(interval: int, acceleration: int, deceleration: 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.