StreamPeer

Hereda: RefCounted < Object

Heredado por: StreamPeerBuffer, StreamPeerExtension, StreamPeerGZIP, StreamPeerTCP, StreamPeerTLS

Clase base abstracta para interactuar con tranmisiones.

Descripción

StreamPeer es una clase base abstracta utilizada principalmente para protocolos basados en tranmisiones (como TCP). Proporciona una API para enviar y recibir datos a través de tranmisiones como datos brutos o strings de texto.

Nota: Al exportar a Android, asegúrate de habilitar el permiso INTERNET en el preset de exportación de Android antes de exportar el proyecto o usar el despliegue con un solo clic. De lo contrario, la comunicación de red de cualquier tipo será bloqueada por Android.

Propiedades

bool

big_endian

false

Métodos

int

get_8()

int

get_16()

int

get_32()

int

get_64()

int

get_available_bytes() const

Array

get_data(bytes: int)

float

get_double()

float

get_float()

float

get_half()

Array

get_partial_data(bytes: int)

String

get_string(bytes: int = -1)

int

get_u8()

int

get_u16()

int

get_u32()

int

get_u64()

String

get_utf8_string(bytes: int = -1)

Variant

get_var(allow_objects: bool = false)

void

put_8(value: int)

void

put_16(value: int)

void

put_32(value: int)

void

put_64(value: int)

Error

put_data(data: PackedByteArray)

void

put_double(value: float)

void

put_float(value: float)

void

put_half(value: float)

Array

put_partial_data(data: PackedByteArray)

void

put_string(value: String)

void

put_u8(value: int)

void

put_u16(value: int)

void

put_u32(value: int)

void

put_u64(value: int)

void

put_utf8_string(value: String)

void

put_var(value: Variant, full_objects: bool = false)


Descripciones de Propiedades

bool big_endian = false 🔗

  • void set_big_endian(value: bool)

  • bool is_big_endian_enabled()

Si es true, este StreamPeer usará el formato big-endian para codificar y decodificar.


Descripciones de Métodos

int get_8() 🔗

Obtiene un byte con signo del stream.


int get_16() 🔗

Obtiene un valor con signo de 16 bits del stream.


int get_32() 🔗

Obtiene un valor con signo de 32 bits del stream.


int get_64() 🔗

Obtiene un valor con signo de 64 bits del stream.


int get_available_bytes() const 🔗

Devuelve la cantidad de bytes que este StreamPeer tiene disponible.


Array get_data(bytes: int) 🔗

Devuelve un trozo de datos con los bytes recibidos. El número de bytes a recibir puede solicitarse en el argumento bytes. Si no hay suficientes bytes disponibles, la función se bloqueará hasta que se reciba la cantidad deseada. Esta función devuelve dos valores, un código Error y un array de datos.


float get_double() 🔗

Consigue un real de double-precision del stream.


float get_float() 🔗

Consigue un real de single-precision del stream.


float get_half() 🔗

Obtiene un float de precisión media de la transmisión.


Array get_partial_data(bytes: int) 🔗

Devuelve un fragmento de datos con los bytes recibidos. La cantidad de bytes a recibir se puede solicitar en el argumento bytes. Si no hay suficientes bytes disponibles, la función devolverá cuántos se recibieron realmente. Esta función devuelve dos valores: un código Error y un array de datos.


String get_string(bytes: int = -1) 🔗

Obtiene una string ASCII con una longitud de bytes bytes del flujo. Si bytes es negativo (por defecto), la longitud se leerá del flujo utilizando el proceso inverso de put_string().


int get_u8() 🔗

Obtiene un byte sin signo del stream.


int get_u16() 🔗

Obtiene un valor de 16 bits sin signo de la corriente.


int get_u32() 🔗

Obtiene un valor de 32 bits sin signo del stream.


int get_u64() 🔗

Obtiene un valor de 64 bits sin signo del stream.


String get_utf8_string(bytes: int = -1) 🔗

Gets a UTF-8 string with byte-length bytes from the stream (this decodes the string sent as UTF-8). If bytes is negative (default) the length will be read from the stream using the reverse process of put_utf8_string().


Variant get_var(allow_objects: bool = false) 🔗

Gets a Variant from the stream. If allow_objects is true, decoding objects is allowed.

Internally, this uses the same decoding mechanism as the @GlobalScope.bytes_to_var() method.

Warning: Deserialized objects can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threats such as remote code execution.


void put_8(value: int) 🔗

Pone un byte con signo en el stream.


void put_16(value: int) 🔗

Pone un valor con signo de 16 bits en el stream.


void put_32(value: int) 🔗

Pone un valor con signo de 32 bits en el stream.


void put_64(value: int) 🔗

Pone un valor con signo de 64 bits en el stream.


Error put_data(data: PackedByteArray) 🔗

Envía un fragmento de datos a través de la conexión, bloqueando si es necesario hasta que se terminen de enviar los datos. Esta función devuelve un código Error.


void put_double(value: float) 🔗

Pone un real de double-precision en el stream.


void put_float(value: float) 🔗

Pone un real de single-precision en el stream.


void put_half(value: float) 🔗

Puts a half-precision float into the stream.


Array put_partial_data(data: PackedByteArray) 🔗

Sends a chunk of data through the connection. If all the data could not be sent at once, only part of it will. This function returns two values, an Error code and an integer, describing how much data was actually sent.


void put_string(value: String) 🔗

Puts a zero-terminated ASCII string into the stream prepended by a 32-bit unsigned integer representing its size.

Note: To put an ASCII string without prepending its size, you can use put_data():

put_data("Hello world".to_ascii_buffer())

void put_u8(value: int) 🔗

Pone un byte sin signo en el stream.


void put_u16(value: int) 🔗

Pone un valor de 16 bits sin signo en el stream.


void put_u32(value: int) 🔗

Pone un valor de 32 bits sin signo en el stream.


void put_u64(value: int) 🔗

Pone un valor de 64 bits sin signo en stream.


void put_utf8_string(value: String) 🔗

Puts a zero-terminated UTF-8 string into the stream prepended by a 32 bits unsigned integer representing its size.

Note: To put a UTF-8 string without prepending its size, you can use put_data():

put_data("Hello world".to_utf8_buffer())

void put_var(value: Variant, full_objects: bool = false) 🔗

Puts a Variant into the stream. If full_objects is true encoding objects is allowed (and can potentially include code).

Internally, this uses the same encoding mechanism as the @GlobalScope.var_to_bytes() method.