MultiplayerPeer

Hereda: PacketPeer < RefCounted < Object

Heredado por: ENetMultiplayerPeer, MultiplayerPeerExtension, OfflineMultiplayerPeer, WebRTCMultiplayerPeer, WebSocketMultiplayerPeer

Abstract class for specialized PacketPeers used by the MultiplayerAPI.

Descripción

Manages the connection with one or more remote peers acting as server or client and assigning unique IDs to each of them. See also MultiplayerAPI.

Note: The MultiplayerAPI protocol is an implementation detail and isn't meant to be used by non-Godot servers. It may change without notice.

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.

Tutoriales

Propiedades

bool

refuse_new_connections

false

int

transfer_channel

0

TransferMode

transfer_mode

2

Métodos

void

close()

void

disconnect_peer(peer: int, force: bool = false)

int

generate_unique_id() const

ConnectionStatus

get_connection_status() const

int

get_packet_channel() const

TransferMode

get_packet_mode() const

int

get_packet_peer() const

int

get_unique_id() const

bool

is_server_relay_supported() const

void

poll()

void

set_target_peer(id: int)


Señales

peer_connected(id: int) 🔗

Emitted when a remote peer connects.


peer_disconnected(id: int) 🔗

Emitted when a remote peer has disconnected.


Enumeraciones

enum ConnectionStatus: 🔗

ConnectionStatus CONNECTION_DISCONNECTED = 0

El MultiplayerPeer está desconectado.

ConnectionStatus CONNECTION_CONNECTING = 1

El MultiplayerPeer se está conectando actualmente a un servidor.

ConnectionStatus CONNECTION_CONNECTED = 2

El MultiplayerPeer está conectado.


enum TransferMode: 🔗

TransferMode TRANSFER_MODE_UNRELIABLE = 0

No se reconocen los paquetes, no se hacen intentos de reenvío de los paquetes perdidos. Los paquetes pueden llegar en cualquier orden. Potencialmente más rápido que TRANSFER_MODE_UNRELIABLE_ORDERED. Utilícela para datos no críticos, y siempre considere si el orden importa.

TransferMode TRANSFER_MODE_UNRELIABLE_ORDERED = 1

No se reconocen los paquetes, no se hacen intentos de reenvío de los paquetes perdidos. Los paquetes se reciben en el orden en que fueron enviados. Potencialmente más rápido que TRANSFER_MODE_RELIABLE. Se utiliza para datos no críticos o datos que estarían desactualizados si se recibieran tarde debido a un intento de reenvío de todas formas, por ejemplo, datos de movimiento y de posición.

TransferMode TRANSFER_MODE_RELIABLE = 2

Los paquetes deben ser recibidos y se debe intentar reenviarlos hasta que se acuse recibo de los mismos. Los paquetes deben ser recibidos en el orden en que fueron enviados. Es el modo de transferencia más fiable, pero potencialmente el más lento debido a la sobrecarga. Se utiliza para los datos críticos que deben transmitirse y llegar en orden, por ejemplo, una capacidad que se está activando o un mensaje de chat. Considera cuidadosamente si la información es realmente crítica, y utilícela con moderación.


Constantes

TARGET_PEER_BROADCAST = 0 🔗

Packets are sent to all connected peers.

TARGET_PEER_SERVER = 1 🔗

Packets are sent to the remote peer acting as server.


Descripciones de Propiedades

bool refuse_new_connections = false 🔗

  • void set_refuse_new_connections(value: bool)

  • bool is_refusing_new_connections()

Si es true, este MultiplayerPeer rechaza las nuevas conexiones.


int transfer_channel = 0 🔗

  • void set_transfer_channel(value: int)

  • int get_transfer_channel()

The channel to use to send packets. Many network APIs such as ENet and WebRTC allow the creation of multiple independent channels which behaves, in a way, like separate connections. This means that reliable data will only block delivery of other packets on that channel, and ordering will only be in respect to the channel the packet is being sent on. Using different channels to send different and independent state updates is a common way to optimize network usage and decrease latency in fast-paced games.

Note: The default channel (0) actually works as 3 separate channels (one for each TransferMode) so that TRANSFER_MODE_RELIABLE and TRANSFER_MODE_UNRELIABLE_ORDERED does not interact with each other by default. Refer to the specific network API documentation (e.g. ENet or WebRTC) to learn how to set up channels correctly.


TransferMode transfer_mode = 2 🔗

The manner in which to send packets to the target peer. See the set_target_peer() method.


Descripciones de Métodos

void close() 🔗

Immediately close the multiplayer peer returning to the state CONNECTION_DISCONNECTED. Connected peers will be dropped without emitting peer_disconnected.


void disconnect_peer(peer: int, force: bool = false) 🔗

Disconnects the given peer from this host. If force is true the peer_disconnected signal will not be emitted for this peer.


int generate_unique_id() const 🔗

Devuelve un entero generado aleatoriamente que se puede usar como un ID único de red.


ConnectionStatus get_connection_status() const 🔗

Devuelve el estado actual de la conexión.


int get_packet_channel() const 🔗

Devuelve el canal por el que se recibió el siguiente paquete disponible. Véase PacketPeer.get_available_packet_count().


TransferMode get_packet_mode() const 🔗

Devuelve el modo de transferencia que utilizó el par remoto para enviar el siguiente paquete disponible. Véase PacketPeer.get_available_packet_count().


int get_packet_peer() const 🔗

Devuelve el ID del MultiplayerPeer que envió el siguiente paquete disponible. Véase PacketPeer.get_available_packet_count().


int get_unique_id() const 🔗

Devuelve el ID de este MultiplayerPeer.


bool is_server_relay_supported() const 🔗

Devuelve true si el servidor puede actuar como un repetidor en la configuración actual. Es decir, si la MultiplayerAPI de nivel superior debe notificar a los clientes conectados de otros peers, e implementar un protocolo de retransmisión para permitir la comunicación entre ellos.


void poll() 🔗

Espera hasta 1 segundo para recibir un nuevo evento de red.


void set_target_peer(id: int) 🔗

Sets the peer to which packets will be sent.

The id can be one of: TARGET_PEER_BROADCAST to send to all connected peers, TARGET_PEER_SERVER to send to the peer acting as server, a valid peer ID to send to that specific peer, a negative peer ID to send to all peers except that one. By default, the target peer is TARGET_PEER_BROADCAST.