GithubHelp home page GithubHelp logo

reactphp / datagram Goto Github PK

View Code? Open in Web Editor NEW
94.0 10.0 26.0 149 KB

Event-driven UDP client and server sockets for ReactPHP.

Home Page: https://reactphp.org/datagram/

License: MIT License

PHP 100.00%
php reactphp datagram

datagram's Introduction

Datagram

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.9

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.

datagram's People

Contributors

andreybolonin avatar cboden avatar clue avatar dinooo13 avatar e3betht avatar enumag avatar jsor avatar nhedger avatar reedy avatar simonfrings avatar wyrihaximus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

datagram's Issues

Create tagged release

Now that the source is imported, we should start adding tags so others can rely on this package.

This package was imported from clue/datagram which already had several tags. These were left out intentionally as this would introduce unnecessary noise in this repository (IMHO).

Ideally, we would release this as v1.0.0 and clean up the CHANGELOG accordingly.

Test suite SEGFAULTs with ext-event

Currently, the test suite seems to SEGFAULT when using ext-event, further investigation is needed, any input is much appreciated ๐Ÿ‘

It looks like this is caused by invoking $loop->run() after the socket has been removed from the loop already, so this should not be an issue in most real world applications.

Missing latest version on packagist

Currently, installing via composer doesn't install latest changes from repo. Changes from this commit are not submitted to packages.ogr.

Hope you'll fix this soon :-)

Factory does not honor /etc/resolv.conf

As as v1.3.0 (see #20), the Factory is hard-coded to default to Google's public DNS server 8.8.8.8. You can explicitly pass a custom Resolver instance like this:

$dnsFactory = new \React\Dns\Resolver\Factory();
$resolver = $dnsFactory->create('127.0.0.1');

$factory = new Factory($loop, $resolver);

Opening this ticket as a reminder - this actually depends on reactphp/dns#29
The same issue also affects the Socket component: reactphp/socket#90

Next steps for Datagram with ReactPHP v3

We're currently moving forward with working on ReactPHP v3 and releasing the roadmap tickets for all our components (see reactphp/event-loop#271 and others). We still have some components that we haven't finalized plans for, especially with the next major version approaching. It's important to address how we can make sure these components are aligned with the upcoming ReactPHP v3.

To give some background information, the reactphp/datagram project has by far the least amount of installations (currently ~400k) compared to the other ReactPHP components (~10M - 50M) and is not required as a dependency by any of them. This project is mostly used for datagram sockets on client and server side, which could also be integrated as part of the reactphp/socket component in the future.

The Datagram component will most definitely receive some kind of compatibility to support datagram sockets with ReactPHP v3. This could lead to a releasing a reactphp/datagram v3, making just the v1 compatible or we could perhaps deprecate this component and reuse the logic elsewhere as needed?

Happy about input on this, so let's discuss possible options and decide on what makes the most sense ๐Ÿš€

Multiple clients connections on same port?

Hi guys,
this is my first time implementing a UDP server.

I would like to understand if this can handle hundreds of incoming connections per second on the same port.
Is there something I can do to lose fewer packets?

Thanks!

Feature proposal - $client->send() - return a Promise

For now, there is no way with the client to send data, THEN close the stream when everything is sent. The $client->send('message) is not in a Promise, so doing the following will not (always) work, as the stream may be closed before everything is sent:

$client->send('chain1');
$client->send('chain2');
$client->close();

Should it be possible to have a similar function, which would returns a Promise? This way, we would have a clean way to send messages, THEN closing the stream.
For example:

$client->sendInPromise('chain1chain 2')->then(function() use ($client) {$client->close()});

Support for AF_UNIX/SOCK_SEQPACKET sockets

Hi!

Is there a way to use this project to create a Server that can accept socket connections created using AF_UNIX/SOCK_SEQPACKET?

This might not work with the StreamSelectLoop since these sockets work with socket_select rather than stream_select.

Some resources:

Stream Video

Have a nice day. Thanks for a good package.
But i have some question 2 u.
Can i get a video stream (create server with open UDP socket) from an other server (need UDP protocol) and output it for some users (clients) via e.g. Ratchet in real-time?
And save some length of this stream?
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.