الصيغة
RakNet.OnPacketReceive.Connect(callback: (packet: RakNetPacket) -> ()): RakNetSignalConnectionأسماء بديلة
raknet.OnPacketReceive.Connectالوسائط
| الاسم | النوع | الوصف |
|---|---|---|
callback | (packet: RakNetPacket) -> () | Function called with each observed incoming RakNetPacket. |
القيم الراجعة
| الاسم | النوع | الوصف |
|---|---|---|
connection | RakNetSignalConnection | Connection object with Disconnect and Connected. |
الوصف
Connects a callback to the OnPacketReceive signal table and returns a RakNetSignalConnection. The callback receives a RakNetPacket while the packet is valid.
استدعه مع 1 parameter: callback. يوضح جدول arguments القيم المطلوبة والقيم التي تضبط السلوك.
يعيد connection (RakNetSignalConnection). استخدم جدول returns للفصل بين قيم النجاح ونتائج nil والأخطاء القابلة للمعالجة.
مثال
Use the signal-style API to observe incoming packets and disconnect the returned connection.
if not RakNet.is_enabled then
return
end
local connection = RakNet.OnPacketReceive:Connect(function(packet)
print(packet.ID, packet.Size)
end)
task.wait(1)
connection:Disconnect()الأنواع
RakNetPacket
Live packet object passed to RakNet hooks and packet signal callbacks. It is only valid during the callback that receives it.
SetData (data: string | buffer | {number}) -> () Replaces packet bytes and updates the packet id from the first byte, or 0 for empty data.Block () -> () Marks the packet as blocked.Ignore () -> () Alias that resolves to Block.AsString string Packet bytes as a Lua string.AsArray {number} Packet bytes as a 1-based array of numbers.AsBuffer buffer Packet bytes as a buffer.Data buffer Packet bytes as a buffer.ID number Packet id value. PacketId, PacketID, and Id resolve to the same value.Priority number Packet priority value.Reliability number Packet reliability value.OrderingChannel number Packet ordering channel value.SystemIdentifier string Packet system identifier as decimal string.Broadcast boolean Packet broadcast flag.ForceReceiptNumber number Packet receipt number.Size number Number of bytes in the packet data.RakNetSignalConnection
Connection object returned by RakNet.OnPacketSend.Connect and RakNet.OnPacketReceive.Connect.
Disconnect () -> () Removes the connection from the packet signal.Connected boolean true while the connection still exists for the current RakNet hook generation.