Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reactphp/datagram
Event-driven UDP client and server sockets for ReactPHP.
https://github.com/reactphp/datagram
datagram php reactphp
Last synced: 5 days ago
JSON representation
Event-driven UDP client and server sockets for ReactPHP.
- Host: GitHub
- URL: https://github.com/reactphp/datagram
- Owner: reactphp
- License: mit
- Created: 2014-02-03T13:30:50.000Z (almost 11 years ago)
- Default Branch: 1.x
- Last Pushed: 2024-01-04T09:11:44.000Z (10 months ago)
- Last Synced: 2024-04-13T16:34:16.856Z (7 months ago)
- Topics: datagram, php, reactphp
- Language: PHP
- Homepage: https://reactphp.org/datagram/
- Size: 146 KB
- Stars: 94
- Watchers: 10
- Forks: 26
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Datagram
[![CI status](https://github.com/reactphp/datagram/actions/workflows/ci.yml/badge.svg)](https://github.com/reactphp/datagram/actions)
[![installs on Packagist](https://img.shields.io/packagist/dt/react/datagram?color=blue&label=installs%20on%20Packagist)](https://packagist.org/packages/react/datagram)Event-driven UDP datagram socket client and server for [ReactPHP](https://reactphp.org).
## Quickstart example
Once [installed](#install), you can use the following code to connect to an UDP server listening on
`localhost:1234` and send and receive UDP datagrams:```php
$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](examples).
## Usage
This library's API is modelled after node.js's API for
[UDP / Datagram Sockets (dgram.Socket)](https://nodejs.org/api/dgram.html).## Install
The recommended way to install this library is [through Composer](https://getcomposer.org/).
[New to Composer?](https://getcomposer.org/doc/00-intro.md)This project follows [SemVer](https://semver.org/).
This will install the latest supported version:```bash
composer require react/datagram:^1.10
```See also the [CHANGELOG](CHANGELOG.md) 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](https://getcomposer.org/):```bash
composer install
```To run the test suite, go to the project root and run:
```bash
vendor/bin/phpunit
```## License
MIT, see [LICENSE file](LICENSE).