Abstraction and base class for stream-based protocols.
    public abstract class StreamPeer : Reference

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

Inheritance Chain

Derived Classes

Properties

    public bool BigEndian { get; set; }

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

Methods

    public short Get16()

    public int Get32()

Gets a signed 32-bit value from the stream.

    public long Get64()

    public sbyte Get8()

    public int GetAvailableBytes()

Returns the amount of bytes this StreamPeer has available.

    public Godot.Collections.Array GetData(int bytes)

Returns a chunk data with the received bytes. The amount of bytes to be received can be requested in the bytes argument. If not enough bytes are available, the function will block until the desired amount is received. This function returns two values, an [enum @GlobalScope.Error] code and a data array.

    public double GetDouble()

    public float GetFloat()

Gets a single-precision float from the stream.

    public Godot.Collections.Array GetPartialData(int bytes)

Returns a chunk data with the received bytes. The amount of bytes to be received can be requested in the “bytes” argument. If not enough bytes are available, the function will return how many were actually received. This function returns two values, an [enum @GlobalScope.Error] code, and a data array.

    public string GetString(int bytes = -1)

Gets a 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 PutString(string).

    public ushort GetU16()

    public uint GetU32()

    public ulong GetU64()

    public byte GetU8()

    public string GetUtf8String(int bytes = -1)

Gets an 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 PutUtf8String(string).

    public object GetVar(bool allowObjects = false)

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

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.

    [Obsolete("IsBigEndianEnabled is deprecated. Use the BigEndian property instead.")]
    public bool IsBigEndianEnabled()

Getter for BigEndian

    public void Put16(short value)

    public void Put32(int value)

Puts a signed 32-bit value into the stream.

    public void Put64(long value)

    public void Put8(sbyte value)

    public Error PutData(byte[] data)

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

    public void PutDouble(double value)

    public void PutFloat(float value)

Puts a single-precision float into the stream.

    public Godot.Collections.Array PutPartialData(byte[] data)

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 [enum @GlobalScope.Error] code and an integer, describing how much data was actually sent.

    public void PutString(string value)

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 PutData(byte[]):

[codeblock]

put_data(“Hello world”.to_ascii())

[/codeblock]

    public void PutU16(ushort value)

    public void PutU32(uint value)

    public void PutU64(ulong value)

    public void PutU8(byte value)

    public void PutUtf8String(string value)

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

Note: To put an UTF-8 string without prepending its size, you can use PutData(byte[]):

[codeblock]

put_data(“Hello world”.to_utf8())

[/codeblock]

    public void PutVar(object value, bool fullObjects = false)

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

    [Obsolete("SetBigEndian is deprecated. Use the BigEndian property instead.")]
    public void SetBigEndian(bool enable)

Setter for BigEndian

Tags: