OpenSwoole Server sendto

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\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.

OpenSwoole\Server->sendto Rules

  • The OpenSwoole server has to listen on the port of UDP if an IPv4 address is used
  • When sending data to an IPv6 address, the OpenSwoole 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 September 1, 2022