Swoole Server sendto

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


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Server->sendto(string $ip, int $port, string $data, int $serverSocket = -1): bool

Parameters

ip

The IP address of the UDP remote server, supports both IPv4 and IPv6, returns an error if incorrect

port

The port of the UDP server to connect to, returns an error if incorrect

data

Specify the data to send over the UDP connection

serverSocket

Specify a socket to use which will transmit the data, requires a file descriptor of the socket from the onPacket event callback, allows for multiple port usage

Return

success

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

Description

Send data to a remote UDP address.

Swoole\Server->sendto Rules

  • The Swoole server has to listen on the port of UDP if an IPv4 address is used
  • When sending data to an IPv6 address, the Swoole server has to listen on the port of UDP6

Example

<?php
$server->sendto('127.0.0.1', 9502, "hello world");

$server->sendto('2600:3c00::f03c:91ff:fe73:e98f', 9501, "hello world");
Last updated on August 31, 2022