Index · Object → RefCounted → StreamPeer

StreamPeer

Abstract base class for interacting with streams.

Inherited by (5): StreamPeerBufferStreamPeerExtensionStreamPeerGZIPStreamPeerSocketStreamPeerTLS
Class Description

StreamPeer is an abstract base class mostly used for stream-based protocols (such as TCP). It provides an API for sending and receiving data through streams as raw data or strings.

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.

Properties

var big_endian: bool = false

If true, this StreamPeer will using big-endian format for encoding and decoding.

Methods

func get_8() -> int

Gets a signed byte from the stream.

func get_16() -> int

Gets a signed 16-bit value from the stream.

func get_32() -> int

Gets a signed 32-bit value from the stream.

func get_64() -> int

Gets a signed 64-bit value from the stream.

func get_available_bytes() -> int

Returns the number of bytes this StreamPeer has available.

func get_data(bytes: int) -> Array

Returns a chunk data with the received bytes, as an Array containing two elements: an Error constant and a PackedByteArray. bytes is the number of bytes to be received. If not enough bytes are available, the function will block until the desired amount is received.

func get_double() -> float

Gets a double-precision float from the stream.

func get_float() -> float

Gets a single-precision float from the stream.

func get_half() -> float

Gets a half-precision float from the stream.

func get_partial_data(bytes: int) -> Array

Returns a chunk data with the received bytes, as an Array containing two elements: an Error constant and a PackedByteArray. bytes is the number of bytes to be received. If not enough bytes are available, the function will return how many were actually received.

func get_string(bytes: int = -1) -> String

Gets an ASCII string with byte-length bytes from the stream. If bytes is negative (default) the length will be read from the stream using the reverse process of put_string().

func get_u8() -> int

Gets an unsigned byte from the stream.

func get_u16() -> int

Gets an unsigned 16-bit value from the stream.

func get_u32() -> int

Gets an unsigned 32-bit value from the stream.

func get_u64() -> int

Gets an unsigned 64-bit value from the stream.

func get_utf8_string(bytes: int = -1) -> String

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().

func get_var(allow_objects: bool = false) -> Variant

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

Internally, this uses the same decoding mechanism as the 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.

func put_8(value: int) -> void

Puts a signed byte into the stream.

func put_16(value: int) -> void

Puts a signed 16-bit value into the stream.

func put_32(value: int) -> void

Puts a signed 32-bit value into the stream.

func put_64(value: int) -> void

Puts a signed 64-bit value into the stream.

func put_data(data: PackedByteArray) -> Error

Sends a chunk of data through the connection, blocking if necessary until the data is done sending. This function returns an Error code.

func put_double(value: float) -> void

Puts a double-precision float into the stream.

func put_float(value: float) -> void

Puts a single-precision float into the stream.

func put_half(value: float) -> void

Puts a half-precision float into the stream.

func put_partial_data(data: PackedByteArray) -> Array

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.

func put_string(value: String) -> void

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())
func put_u8(value: int) -> void

Puts an unsigned byte into the stream.

func put_u16(value: int) -> void

Puts an unsigned 16-bit value into the stream.

func put_u32(value: int) -> void

Puts an unsigned 32-bit value into the stream.

func put_u64(value: int) -> void

Puts an unsigned 64-bit value into the stream.

func put_utf8_string(value: String) -> void

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())
func put_var(value: Variant, full_objects: bool = false) -> void

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 var_to_bytes() method.

Inherited from RefCounted (4)
func init_ref() -> bool
func reference() -> bool
func unreference() -> bool
Inherited from Object (62)
func _get(property: StringName) -> Variant
func _get_property_list() -> Dictionary[]
func _init() -> void
func _iter_get(iter: Variant) -> Variant
func _iter_init(iter: Array) -> bool
func _iter_next(iter: Array) -> bool
func _notification(what: int) -> void
func _set(property: StringName, value: Variant) -> bool
func _to_string() -> String
func _validate_property(property: Dictionary) -> void
func add_user_signal(signal: String, arguments: Array = []) -> void
func call(method: StringName) -> Variant
func callv(method: StringName, arg_array: Array) -> Variant
func cancel_free() -> void
func connect(signal: StringName, callable: Callable, flags: int = 0) -> Error
func disconnect(signal: StringName, callable: Callable) -> void
func emit_signal(signal: StringName) -> Error
func free() -> void
func get(property: StringName) -> Variant
func get_class() -> String
func get_incoming_connections() -> Dictionary[]
func get_indexed(property_path: NodePath) -> Variant
func get_meta(name: StringName, default: Variant = null) -> Variant
func get_meta_list() -> StringName[]
func get_method_list() -> Dictionary[]
func get_property_list() -> Dictionary[]
func get_signal_connection_list(signal: StringName) -> Dictionary[]
func get_signal_list() -> Dictionary[]
func has_meta(name: StringName) -> bool
func has_method(method: StringName) -> bool
func has_signal(signal: StringName) -> bool
func is_class(class: StringName) -> bool
func is_connected(signal: StringName, callable: Callable) -> bool
func notification(what: int, reversed: bool = false) -> void
func remove_meta(name: StringName) -> void
func remove_user_signal(signal: StringName) -> void
func set(property: StringName, value: Variant) -> void
func set_block_signals(enable: bool) -> void
func set_deferred(property: StringName, value: Variant) -> void
func set_indexed(property_path: NodePath, value: Variant) -> void
func set_message_translation(enable: bool) -> void
func set_meta(name: StringName, value: Variant) -> void
func set_script(script: Variant) -> void
func set_translation_domain(domain: StringName) -> void
func to_string() -> String
func tr(message: StringName, context: StringName = &"") -> String
func tr_n(message: StringName, plural_message: StringName, n: int, context: StringName = &"") -> String

Signals

Inherited from Object (2)