WebSocketClient¶
Inherits: WebSocketMultiplayerPeer < NetworkedMultiplayerPeer < PacketPeer < Reference < Object
Una implementación del cliente WebSocket.
Descripción¶
Esta clase implementa un cliente WebSocket compatible con cualquier servidor WebSocket compatible con RFC 6455.
Este cliente puede ser usado opcionalmente como un par de red para la MultiplayerAPI.
Después de iniciar el cliente (connect_to_url), necesitarás NetworkedMultiplayerPeer.poll a intervalos regulares (por ejemplo, dentro de Node._process).
Recibirá las señales apropiadas cuando se conecte, desconecte o cuando haya nuevos datos disponibles.
Propiedades¶
Métodos¶
connect_to_url ( String url, PoolStringArray protocols=PoolStringArray( ), bool gd_mp_api=false, PoolStringArray custom_headers=PoolStringArray( ) ) |
|
void |
disconnect_from_host ( int code=1000, String reason="" ) |
get_connected_host ( ) const |
|
get_connected_port ( ) const |
Señales¶
connection_closed ( bool was_clean_close )
Emitido cuando la conexión con el servidor se cierra. was_clean_close
será true
si la conexión se cerró limpiamente.
connection_error ( )
Emitido cuando la conexión con el servidor falla.
connection_established ( String protocol )
Emitido cuando se establece una conexión con el servidor, el protocol
contendrá el subprotocolo acordado con el servidor.
data_received ( )
Emitido cuando se recibe un mensaje de WebSocket.
Nota: Esta señal es no emitida cuando se usa como par multijugador de alto nivel.
Emitido cuando el servidor solicita un cierre limpio. Debes seguir preguntando hasta que recibas una señal connection_closed para lograr el cierre limpio. Consulta el WebSocketPeer.close para más detalles.
Descripciones de Propiedades¶
X509Certificate trusted_ssl_certificate
Setter |
set_trusted_ssl_certificate(value) |
Getter |
get_trusted_ssl_certificate() |
Si se especifica, este X509Certificate será el único aceptado cuando se conecte a un host SSL. Cualquier otro certificado proporcionado por el servidor se considerará inválido.
Nota: La especificación de un certificado personalizado trusted_ssl_certificate
no es compatible con las exportaciones en HTML5 debido a las restricciones de los navegadores.
bool verify_ssl
Setter |
set_verify_ssl_enabled(value) |
Getter |
is_verify_ssl_enabled() |
Si true
, la verificación del certificado SSL está activada.
Nota: Debe especificar los certificados que se utilizarán en la Configuración del proyecto para que funcione cuando se exporte.
Descripciones de Métodos¶
Error connect_to_url ( String url, PoolStringArray protocols=PoolStringArray( ), bool gd_mp_api=false, PoolStringArray custom_headers=PoolStringArray( ) )
Connects to the given URL requesting one of the given protocols
as sub-protocol. If the list empty (default), no sub-protocol will be requested.
If true
is passed as gd_mp_api
, the client will behave like a network peer for the MultiplayerAPI, connections to non-Godot servers will not work, and data_received will not be emitted.
If false
is passed instead (default), you must call PacketPeer functions (put_packet
, get_packet
, etc.) on the WebSocketPeer returned via get_peer(1)
and not on this object directly (e.g. get_peer(1).put_packet(data)
).
You can optionally pass a list of custom_headers
to be added to the handshake HTTP request.
Note: To avoid mixed content warnings or errors in HTML5, you may have to use a url
that starts with wss://
(secure) instead of ws://
. When doing so, make sure to use the fully qualified domain name that matches the one defined in the server's SSL certificate. Do not connect directly via the IP address for wss://
connections, as it won't match with the SSL certificate.
Note: Specifying custom_headers
is not supported in HTML5 exports due to browsers restrictions.
Desconecta este cliente del host conectado. Ver WebSocketPeer.close para más información.
String get_connected_host ( ) const
Devuelve la dirección IP del host conectado actualmente.
int get_connected_port ( ) const
Devuelve el puerto IP del host conectado actualmente.