raknet. OnPacketReceive: Once Synchronous
RakNet.OnPacketReceive:Once
Observe just the next incoming packet. The one-shot connection unregisters before the callback, so the callback cannot accidentally receive a second packet.
raknet.OnPacketReceive:Once(callback: (RakNetPacket) -> ()) -> RakNetConnectionParameters
Call this method with a raknet.OnPacketReceive 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 that can also be disconnected before it fires.
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.OnPacketReceive:Once(function(packet)
print("Next incoming ID:", packet.ID)
end)
task.delay(10, function() connection:Disconnect() end)
end