react/datagram

Event-driven UDP datagram socket client and server for ReactPHP

Package info

github.com/reactphp/datagram

pkg:composer/react/datagram

Fund package maintenance!

Open Collective

Statistics

Installs: 864 734

Dependents: 41

Suggesters: 0

Stars: 99

Open Issues: 2

v1.10.0 2024-09-06 11:22 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 9236e1f5a67a6029be17d551e9858c487836c301

clientserverSocketasyncudpdatagramdgramreactphp

This package is auto-updated.

Last update: 2026-06-10 22:43:50 UTC


README

πŸ‘ CI status
πŸ‘ installs on Packagist

Event-driven UDP datagram socket client and server for ReactPHP.

Quickstart example

Once installed, you can use the following code to connect to an UDP server listening on localhost:1234 and send and receive UDP datagrams:

$factory = new React\Datagram\Factory();

$factory->createClient('localhost:1234')->then(function (React\Datagram\Socket $client) {
 $client->send('first');

 $client->on('message', function($message, $serverAddress, $client) {
 echo 'received "' . $message . '" from ' . $serverAddress. PHP_EOL;
 });
});

See also the examples.

Usage

This library's API is modelled after node.js's API for UDP / Datagram Sockets (dgram.Socket).

Install

The recommended way to install this library is through Composer. New to Composer?

This project follows SemVer. This will install the latest supported version:

composer require react/datagram:^1.10

See also the CHANGELOG for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP extensions and supports running on legacy PHP 5.3 through current PHP 8+ and HHVM. It's highly recommended to use PHP 7+ for this project.

Tests

To run the test suite, you first need to clone this repo and then install all dependencies through Composer:

composer install

To run the test suite, go to the project root and run:

vendor/bin/phpunit

License

MIT, see LICENSE file.