NetworkedMultiplayerENet

Inherits: NetworkedMultiplayerPeer < PacketPeer < Reference < Object

Implementación de PacketPeer usando la biblioteca ENet.

Descripción

A PacketPeer implementation that should be passed to SceneTree.network_peer after being initialized as either a client or server. Events can then be handled by connecting to SceneTree signals.

ENet's purpose is to provide a relatively thin, simple and robust network communication layer on top of UDP (User Datagram Protocol).

Note: ENet only uses UDP, not TCP. When forwarding the server port to make your server accessible on the public Internet, you only need to forward the server port in UDP. You can use the UPNP class to try to forward the server port automatically when starting the server.

Tutoriales

Propiedades

bool

always_ordered

false

int

channel_count

3

CompressionMode

compression_mode

1

String

dtls_hostname

""

bool

dtls_verify

true

bool

refuse_new_connections

false (overrides NetworkedMultiplayerPeer)

bool

server_relay

true

int

transfer_channel

-1

TransferMode

transfer_mode

2 (overrides NetworkedMultiplayerPeer)

bool

use_dtls

false

Métodos

void

close_connection ( int wait_usec=100 )

Error

create_client ( String address, int port, int in_bandwidth=0, int out_bandwidth=0, int client_port=0 )

Error

create_server ( int port, int max_clients=32, int in_bandwidth=0, int out_bandwidth=0 )

void

disconnect_peer ( int id, bool now=false )

int

get_last_packet_channel ( ) const

int

get_packet_channel ( ) const

String

get_peer_address ( int id ) const

int

get_peer_port ( int id ) const

void

set_bind_ip ( String ip )

void

set_dtls_certificate ( X509Certificate certificate )

void

set_dtls_key ( CryptoKey key )

void

set_peer_timeout ( int id, int timeout_limit, int timeout_min, int timeout_max )

Enumeraciones

enum CompressionMode:

  • COMPRESS_NONE = 0 --- No compression. This uses the most bandwidth, but has the upside of requiring the fewest CPU resources. This option may also be used to make network debugging using tools like Wireshark easier.

  • COMPRESS_RANGE_CODER = 1 --- ENet's built-in range encoding. Works well on small packets, but is not the most efficient algorithm on packets larger than 4 KB.

  • COMPRESS_FASTLZ = 2 --- Compresión FastLZ. Esta opción utiliza menos recursos de CPU en comparación con COMPRESS_ZLIB, a expensas de utilizar más ancho de banda.

  • COMPRESS_ZLIB = 3 --- Zlib compression. This option uses less bandwidth compared to COMPRESS_FASTLZ, at the expense of using more CPU resources. Note that this algorithm is not very efficient on packets smaller than 4 KB. Therefore, it's recommended to use other compression algorithms in most cases.

  • COMPRESS_ZSTD = 4 --- Compresión estándar.

Descripciones de Propiedades

  • bool always_ordered

Default

false

Setter

set_always_ordered(value)

Getter

is_always_ordered()

Fuerza el orden de los paquetes cuando se utiliza NetworkedMultiplayerPeer.TRANSFER_MODE_UNRELIABLE (por lo que se comporta de manera similar a NetworkedMultiplayerPeer.TRANSFER_MODE_UNRELIABLE_ORDERED). Esta es la única manera de usar el sistema de pedidos con el sistema RPC.


  • int channel_count

Default

3

Setter

set_channel_count(value)

Getter

get_channel_count()

El número de canales que será usado por ENet. Los canales se usan para separar diferentes tipos de datos. En el modo fiable o pedido, por ejemplo, la orden de entrega de paquetes se asegura por cada canal. Esto se hace para combatir la latencia y reducir las restricciones de pedido de los paquetes. El estado de entrega de un paquete en un canal no detendrá la entrega de otros paquetes en otro canal.


Default

1

Setter

set_compression_mode(value)

Getter

get_compression_mode()

The compression method used for network packets. These have different tradeoffs of compression speed versus bandwidth, you may need to test which one works best for your use case if you use compression at all.

Note: Most games' network design involve sending many small packets frequently (smaller than 4 KB each). If in doubt, it is recommended to keep the default compression algorithm as it works best on these small packets.

Note: compression_mode must be set to the same value on both the server and all its clients. Clients will fail to connect if the compression_mode set on the client differs from the one set on the server. Prior to Godot 3.4, the default compression_mode was COMPRESS_NONE. Nonetheless, mixing engine versions between clients and server is not recommended and not officially supported.


Default

""

Setter

set_dtls_hostname(value)

Getter

get_dtls_hostname()

The hostname used for DTLS verification, to be compared against the "CN" value in the certificate provided by the server.

When set to an empty string, the address parameter passed to create_client is used instead.


Default

true

Setter

set_dtls_verify_enabled(value)

Getter

is_dtls_verify_enabled()

Habilitar o deshabilitar la verificación del certificado cuando use_dtls true.


Default

true

Setter

set_server_relay_enabled(value)

Getter

is_server_relay_enabled()

Habilitar o deshabilitar la función del servidor que notifica a los clientes de la conexión/desconexión de otros compañeros, y retransmitir mensajes entre ellos. Cuando esta opción es false, los clientes no serán notificados automáticamente de la conexión/desconexión de otros compañeros y no podrán enviarles paquetes a través del servidor.


  • int transfer_channel

Default

-1

Setter

set_transfer_channel(value)

Getter

get_transfer_channel()

Establezca el canal predeterminado que se utilizará para la transferencia de datos. Por defecto, este valor es -1, lo que significa que ENet sólo utilizará 2 canales: uno para los paquetes fiables y otro para los no fiables. El canal 0 está reservado y no puede ser utilizado. Ajustar este miembro a cualquier valor entre 0 y channel_count (excluido) obligará a ENet a utilizar ese canal para enviar datos. Vea channel_count para más información sobre los canales de ENet.


Default

false

Setter

set_dtls_enabled(value)

Getter

is_dtls_enabled()

When enabled, the client or server created by this peer, will use PacketPeerDTLS instead of raw UDP sockets for communicating with the remote peer. This will make the communication encrypted with DTLS at the cost of higher resource usage and potentially larger packet size.

Note: When creating a DTLS server, make sure you setup the key/certificate pair via set_dtls_key and set_dtls_certificate. For DTLS clients, have a look at the dtls_verify option, and configure the certificate accordingly via set_dtls_certificate.

Descripciones de Métodos

  • void close_connection ( int wait_usec=100 )

Cierra la conexión. Ignorado si no se establece ninguna conexión actualmente. Si se trata de un servidor, intenta notificar a todos los clientes antes de desconectarlos por la fuerza. Si se trata de un cliente, simplemente cierra la conexión con el servidor.


Crear el cliente que se conecta a un servidor en la address usando el port especificado. La dirección especificada debe ser un nombre de dominio completamente cualificado (por ejemplo, "www.example.com") o una dirección IP en formato IPv4 o IPv6 (por ejemplo, "192.168.1.1"). El port es el puerto en el que el servidor está escuchando. Los parámetros in_bandwith y out_bandwidth pueden utilizarse para limitar el ancho de banda de entrada y de salida al número dado de bytes por segundo. El valor predeterminado de 0 significa ancho de banda ilimitado. Tenga en cuenta que el ENet dejará caer estratégicamente paquetes en lados específicos de una conexión entre pares para asegurarse de que el ancho de banda del par no se vea sobrepasado. Los parámetros de ancho de banda también determinan el tamaño de la ventana de una conexión que limita la cantidad de paquetes confiables que pueden estar en tránsito en un momento dado. Devuelve @GlobalScope.OK si se creó un cliente, @GlobalScope.ERR_ALREADY_IN_USE si esta instancia NetworkedMultiplayerENet ya tiene una conexión abierta (en cuyo caso necesita llamar primero a close_connection) o @GlobalScope.ERR_CANT_CREATE si no se pudo crear el cliente. Si se especifica client_port, el cliente también escuchará el puerto dado; esto es útil para algunas técnicas de travesía de NAT.


  • Error create_server ( int port, int max_clients=32, int in_bandwidth=0, int out_bandwidth=0 )

Crear un servidor que escuche las conexiones a través de port. El puerto debe ser un puerto disponible y no utilizado entre 0 y 65535. Tenga en cuenta que los puertos por debajo de 1024 son privilegiados y pueden requerir permisos elevados dependiendo de la plataforma. Para cambiar la interfaz en la que escucha el servidor, utilice set_bind_ip. La IP por defecto es el comodín "*", que escucha en todas las interfaces disponibles. max_clients es el número máximo de clientes que se permiten a la vez, se puede utilizar cualquier número hasta 4095, aunque el número alcanzable de clientes simultáneos puede ser muy inferior y depende de la aplicación. Para más detalles sobre los parámetros de ancho de banda, véase create_client. Devuelve @GlobalScope.OK si se ha creado un servidor, @GlobalScope.ERR_ALREADY_IN_USE si esta instancia NetworkedMultiplayerENet ya tiene una conexión abierta (en cuyo caso hay que llamar primero a close_connection) o @GlobalScope.ERR_CANT_CREATE si no se ha podido crear el servidor.


  • void disconnect_peer ( int id, bool now=false )

Desconecta el par dado. Si "ahora" está configurado como true, la conexión se cerrará inmediatamente sin eliminar los mensajes de la cola.


  • int get_last_packet_channel ( ) const

Devuelve el canal del último paquete obtenido a través del PacketPeer.get_packet.


  • int get_packet_channel ( ) const

Devuelve el canal del siguiente paquete que será recuperado a través del PacketPeer.get_packet.


Devuelve la dirección IP del par dado.


  • int get_peer_port ( int id ) const

Devuelve el puerto remoto del par dado.


  • void set_bind_ip ( String ip )

La IP usada cuando se crea un servidor. Está configurada por defecto con el comodín "*", que se une a todas las interfaces disponibles. La IP dada debe estar en formato de dirección IPv4 o IPv6, por ejemplo: "192.168.1.1".


Configure el X509Certificate para usarlo cuando use_dtls sea true[/code Configure el [X509Certificate] para usarlo cuando [member use_dtls] sea [code]true. Para los servidores, también debe configurar la CryptoKey mediante el set_dtls_key.]. Para los servidores, también debe configurar la CryptoKey a través de set_dtls_key.


Configure el X509Certificate para usarlo cuando use_dtls sea true. Para los servidores, también debe configurar la CryptoKey mediante el set_dtls_key.


  • void set_peer_timeout ( int id, int timeout_limit, int timeout_min, int timeout_max )

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_limit 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.