PacketPeer
Abstraction and base class for packet-based protocols.
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
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
public int GetAvailablePacketCount();Returns the number of packets currently available in the ring-buffer.
intGetEncodeBufferMaxSizeint
public int GetEncodeBufferMaxSize();intGetPacketbyte[]
public byte[] GetPacket();Gets a raw packet.
byte[]GetPacketErrorError
public Error GetPacketError();Returns the error state of the last packet received (via PacketPeer.GetPacket and PacketPeer.GetVar).
ErrorGetVarVariant
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.
| Name | Type | Default |
|---|---|---|
allowObjects | bool | false |
VariantPutPacket2 overloads
public Error PutPacket(byte[] buffer);Sends a raw packet.
| Name | Type | Default |
|---|---|---|
buffer | byte[] | — |
Errorpublic Error PutPacket(ReadOnlySpan<byte> buffer);Sends a raw packet.
| Name | Type | Default |
|---|---|---|
buffer | ReadOnlySpan<byte> | — |
ErrorPutVarError
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.
| Name | Type | Default |
|---|---|---|
var | Variant | — |
fullObjects | bool | false |
ErrorSetEncodeBufferMaxSizevoid
public void SetEncodeBufferMaxSize(int maxSize);| Name | Type | Default |
|---|---|---|
maxSize | int | — |