raknet. OnPacketSend: Connect Synchronous
RakNet.OnPacketSend:ConnectRakNet.OnPacketSend:connectraknet.OnPacketSend:connect
Connect a listener to outgoing packet events. It returns a connection object, which is convenient when an observer should live for a specific task or time window.
raknet.OnPacketSend:Connect(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 with a temporary RakNetPacket for each outgoing packet. |
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 with Connected and Disconnect members.
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:Connect(function(packet)
print("Outgoing ID:", packet.ID)
end)
task.delay(5, function() connection:Disconnect() end)
end