> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectreal.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# RakNet.add_send_hook

> Registers a callback for observed outgoing RakNet packets. The callback receives one RakNetPacket while the packet is valid. Registering the same closure again replaces its stored reference. The function returns the callback it was given.

<div className="real-function-page">
  ```lua theme={null}
  RakNet.add_send_hook(callback: (packet: RakNetPacket) -> ()): function
  ```

  ## Alias

  * `raknet.add_send_hook`

  ## Argumen

  <ParamField path={"callback"} type={"(packet: RakNetPacket) -> ()"} required>
    Function called with each observed outgoing RakNetPacket.
  </ParamField>

  ## Return

  <ResponseField name={"callback"} type={"function"}>
    The same callback function that was passed in.
  </ResponseField>

  ## Tipe

  ### RakNetPacket

  Live packet object passed to RakNet hooks and packet signal callbacks. It is only valid during the callback that receives it.

  | Name                 | Type                                                   | Required | Deskripsi                                                                                 |
  | -------------------- | ------------------------------------------------------ | -------- | ----------------------------------------------------------------------------------------- |
  | `SetData`            | `(data: string \| buffer \| &#123;number&#125;) -> ()` | Yes      | Replaces packet bytes and updates the packet id from the first byte, or 0 for empty data. |
  | `Block`              | `() -> ()`                                             | Yes      | Marks the packet as blocked.                                                              |
  | `Ignore`             | `() -> ()`                                             | Yes      | Alias that resolves to Block.                                                             |
  | `AsString`           | `string`                                               | Yes      | Packet bytes as a Lua string.                                                             |
  | `AsArray`            | `&#123;number&#125;`                                   | Yes      | Packet bytes as a 1-based array of numbers.                                               |
  | `AsBuffer`           | `buffer`                                               | Yes      | Packet bytes as a buffer.                                                                 |
  | `Data`               | `buffer`                                               | Yes      | Packet bytes as a buffer.                                                                 |
  | `ID`                 | `number`                                               | Yes      | Packet id value. PacketId, PacketID, and Id resolve to the same value.                    |
  | `Priority`           | `number`                                               | Yes      | Packet priority value.                                                                    |
  | `Reliability`        | `number`                                               | Yes      | Packet reliability value.                                                                 |
  | `OrderingChannel`    | `number`                                               | Yes      | Packet ordering channel value.                                                            |
  | `SystemIdentifier`   | `string`                                               | Yes      | Packet system identifier as decimal string.                                               |
  | `Broadcast`          | `boolean`                                              | Yes      | Packet broadcast flag.                                                                    |
  | `ForceReceiptNumber` | `number`                                               | Yes      | Packet receipt number.                                                                    |
  | `Size`               | `number`                                               | Yes      | Number of bytes in the packet data.                                                       |

  ## Contoh

  Observe outgoing packets with a callback and remove the same callback later.

  ```lua theme={null}
  if not raknet.is_enabled then
      return
  end

  local function onSend(packet)
      print(packet.ID, packet.Size)
  end

  raknet.add_send_hook(onSend)
  task.wait(1)
  raknet.remove_send_hook(onSend)
  ```
</div>
