reckfellENGINE

PacketPeer

Abstraction and base class for packet-based protocols.

On this page
class PacketPeerReckfellSharpInherits RefCounted

Abstraction and base class for packet-based protocols.

PacketPeer is an abstraction and base class for packet-based protocols (such as UDP). It provides an API for sending and receiving packets both as raw data or variables. This makes it easy to transfer data over a protocol, without having to encode data as low-level bytes or having to worry about network ordering. Note: When exporting to Android, make sure to enable the INTERNET permission in the Android export preset before exporting the project or using remote deploy. Otherwise, network communication of any kind will be blocked by Android.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Properties1

EncodeBufferMaxSizeProperty
# EncodeBufferMaxSize
C#
public int EncodeBufferMaxSize { get; set; }

Maximum buffer size allowed when encoding Variants. Raise this value to support heavier memory allocations. The PacketPeer.PutVar method allocates memory on the stack, and the buffer used will grow automatically to the closest power of two to match the size of the Variant. If the Variant is bigger than PacketPeer.EncodeBufferMaxSize, the method will error out with ERR_OUT_OF_MEMORY.

Methods9

GetAvailablePacketCountint
# GetAvailablePacketCount
C#
public int GetAvailablePacketCount();

Returns the number of packets currently available in the ring-buffer.

Returns int
GetEncodeBufferMaxSizeint
# GetEncodeBufferMaxSize
C#
public int GetEncodeBufferMaxSize();
Returns int
GetPacketbyte[]
# GetPacket
C#
public byte[] GetPacket();

Gets a raw packet.

Returns byte[]
GetPacketErrorError
# GetPacketError
C#
public Error GetPacketError();

Returns the error state of the last packet received (via PacketPeer.GetPacket and PacketPeer.GetVar).

Returns Error
GetVarVariant
# GetVar
C#
public Variant GetVar(bool allowObjects = false);

Gets a Variant. If allow_objects is true, decoding objects is allowed. Internally, this uses the same decoding mechanism as the ReckfellApi.BytesToVar 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.

Parameters
NameTypeDefault
allowObjectsboolfalse
Returns Variant
PutPacket2 overloads
# PutPacket · 1/2
C#
public Error PutPacket(byte[] buffer);

Sends a raw packet.

Parameters
NameTypeDefault
bufferbyte[]—
Returns Error
# PutPacket · 2/2
C#
public Error PutPacket(ReadOnlySpan<byte> buffer);

Sends a raw packet.

Parameters
NameTypeDefault
bufferReadOnlySpan<byte>—
Returns Error
PutVarError
# PutVar
C#
public Error PutVar(Variant var, bool fullObjects = false);

Sends a Variant as a packet. If full_objects is true, encoding objects is allowed (and can potentially include code). Internally, this uses the same encoding mechanism as the ReckfellApi.VarToBytes method.

Parameters
NameTypeDefault
varVariant—
fullObjectsboolfalse
Returns Error
SetEncodeBufferMaxSizevoid
# SetEncodeBufferMaxSize
C#
public void SetEncodeBufferMaxSize(int maxSize);
Parameters
NameTypeDefault
maxSizeint—
Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.