Swoole TCP/UDP client callback functions

Events and Callback-functions List

There is no connect and close connection event for UDP. If you have setted the callback function for event connect, it will be called immediately after the UDP client is created.

If you have setted the callback function for event close, it will be called immediately after the UDP client is closed.

Table of Contents

function onConnect(Swoole\Client $client)

connect event happens when the client connect to the server successfully.

<?php
function onConnect(Swoole\Client $client)

For TCP client, it must set the callback function for event connect.

For UDP client, it is optional to set the callback function for event connect.

function onError(Swoole\Client $client)

error event happens when the client fails to connect to the server.

<?php
function onError(Swoole\Client $client)

For UDP client, there is no event error.

function onReceive(Swoole\Client $client, string $data)

The receive event happens when the client receive the data from the server.

<?php
function onReceive(Swoole\Client $client, string $data)

If the client has setted the configuration about eof/length check, the data received would be a whole packet.

function onClose(Swoole\Client $client)

The close event happens when the connection between the client and server is closed.

<?php
function onClose(Swoole\Client $client)

The close event is triggered when the connection is closed by either the server or the client.

function onBufferFull(Swoole\Client $client)

The bufferfull event happens when the buffer reaches the buffer_high_watermark which is setted by $client->buffer_high_watermark. If the buffer is full, it can't send data to the server anymore.

<?php
function onBufferFull(Swoole\Client $client);

function onBufferEmpty(Swoole\Client $client)

The bufferempty event happens when the buffer reaches the buffer_low_watermark which is setted by $client->buffer_low_watermark. If the buffer is empty, it can continue to send data to the server.

<?php
function onBufferEmpty(Swoole\Client $client);