raknet. OnPacketSend: Once Synchronous
RakNet.OnPacketSend:Once
Listen for the next outgoing packet and disconnect automatically before your callback runs. Use it for a one-packet observation without a manual cleanup path.
raknet.OnPacketSend:Once(callback: (RakNetPacket) -> ()) -> RakNetConnectionParameters
Call this method with a raknet.OnPacketSend receiver. The colon supplies self implicitly; a dot call must pass the receiver explicitly.
| Parameter | Type | Description |
|---|---|---|
callback | (RakNetPacket) -> () | Function called once with a temporary RakNetPacket. |
Argument fields
RakNetPacket = {
Data: buffer, AsArray: {number}, AsBuffer: buffer, AsString: string,
Size: number, PacketId: number, ID: number, Id: number, PacketID: number, Priority: number,
Reliability: number, OrderingChannel: number,
SystemIdentifier: string, Broadcast: boolean, ForceReceiptNumber: number
}Returns
RakNetConnectionA RakNetConnection, which can be disconnected early if the packet never arrives.
RakNetConnection = {Connected: boolean, Disconnect: Function, disconnect: Function}Usage notes
The RakNet library must be enabled in Environment settings and connected to an active game generation.
Callbacks must not yield. If a callback raises, Kawaii reports a warning and continues dispatching.
The RakNetPacket view is valid only during its callback. Save fields or copy Data inside the callback if you need them later.
Availability
RakNet is disabled by default. RakNet and raknet are removed when the setting is off; retained references can still call is_enabled().
Example
if raknet.is_enabled() then
local connection = raknet.OnPacketSend:Once(function(packet)
print("Next outgoing ID:", packet.ID)
end)
task.delay(10, function() connection:Disconnect() end)
end