Swoole\Server->on('Packet', fn)

4.x is outdated, please check the latest version 22.x


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Server->on('Packet', Callable $callback)

Parameters

event

The event callback name.

callback

Callable event function.

Return

success

If success, it returns true, otherwise it returns false.

Description

Execute the callback function when the Server is receiving UDP data packets.

The callback function registered on the event packet is executed in the Worker Process which is receiving data.

Example

  • $data the UDP data packet received, may be a string or binary data
  • $clientInfo, this data is an array, information about the connected client

Array example of $clientInfo:

[
  server_socket => 4,
  server_port => 9501,
  address => 127.0.0.1,
  port => 47306,
]

If the Server is listening on both TCP and UDP ports, the Receive callback function is executed when TCP data is received and the Packet callback function is executed when UDP data is received.

Last updated on August 31, 2022