ByteNet Max provides four methods for reacting to incoming data on both packets and queries. Understanding the differences between them helps you write cleaner, safer networking code and avoid memory leaks caused by stale callbacks.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Elitriare/ByteNet-Max/llms.txt
Use this file to discover all available pages before exploring further.
All four listener methods —
listen, listenOnce, disconnectAll, and wait — work identically on both packets and queries. The examples below use packets, but the same patterns apply directly to queries.listen — persistent callback
listen — persistent callback
listen(callback) registers a callback that fires every time the packet or query is received. It returns a disconnect function that you can call at any time to remove that specific listener.listen calls remain active.listenOnce — one-shot callback
listenOnce — one-shot callback
listenOnce(callback) registers a callback that fires exactly once. The listener is automatically disconnected after it fires, so you do not need to call the returned disconnect function under normal conditions. The disconnect function is still returned in case you want to cancel before the first fire.disconnectAll — clear every listener
disconnectAll — clear every listener
disconnectAll() removes every callback registered on that packet or query in a single call. It is equivalent to calling the disconnect function returned by every previous listen or listenOnce call.wait — yield until next event
wait — yield until next event
wait() suspends the current coroutine until the packet or query fires once, then resumes it with the received data. It behaves like a one-shot listener implemented with coroutine.yield, so it does not block the rest of the script.wait is useful for sequential flows where you want to pause execution until a specific event occurs, without setting up a persistent listener.Disconnect pattern in practice
Assign the return value oflisten to a variable so you can disconnect it later. This is the recommended approach for listeners that should be tied to the lifetime of a specific object or state:
table.find and table.remove to locate the listener by reference, so removing it during iteration does not corrupt the listener list.