ReferenceRakNet

raknet.addsendhook

Registers a callback for outgoing packets.

Syntax

raknet.addsendhook(callback: function) -> boolean

Also available as

raknet.add_send_hook

Parameters

ParameterTypeDescription
callbackfunctionFunction accepting one packet object.

Returns

TypeDescription
booleanTrue when the callback is registered.

Description

The callback receives a RakNetPacket with byte representations and metadata. Inspect the packet without changing it to observe traffic. SetData and Block are valid only while this callback is executing; keep it short and avoid yielding. Retain the same callback function to remove it later. Unsupported sessions raise a clear error rather than pretending the callback was installed.

Example

local function inspect(packet)
    print(packet.Direction, packet.Size)
end
raknet.addsendhook(inspect)
raknet.removesendhook(inspect)

These are Game executor contracts. Check build requirements and session lifetimes before using them.