Abstract base class for interacting with streams.
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.
If true, this StreamPeer will using big-endian format for encoding and decoding.
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.
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.
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().
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().
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.
Sends a chunk of data through the connection, blocking if necessary until the data is done sending. This function returns an Error code.
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.
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())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())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.