concerto / sockets
Library for creating event based socket servers and clients based on ReactPHP.
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 660
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Type:concerto-component
Requires
- php: >=5.4.0
- evenement/evenement: 2.0.*
- react/socket: 0.4.*
- react/socket-client: 0.4.*
This package is not auto-updated.
Last update: 2020-08-03 06:42:26 UTC
README
Library for creating event based socket servers and clients based on ReactPHP.
Install
The recommended way to install Sockets is through composer.
{ "require": { "concerto/sockets": "0.*" } }
Usage
Server
use Concerto\Sockets\Server; use React\EventLoop\Factory as EventLoopFactory; $loop = EventLoopFactory::create(); $server = new Server($loop, 'tcp://127.0.0.1:1234'); $server->on('connect', function($conn) { $conn->write("Hello client!\n"); $conn->on('data', function ($data) use ($conn) { $conn->close(); }); }); $server->listen(); $loop->run();
Client
use Concerto\Sockets\Client; use React\EventLoop\Factory as EventLoopFactory; use React\Stream\Stream; $loop = EventLoopFactory::create(); $client = new Client($loop, 'tcp://127.0.0.1:1234'); $client->on('connect', function($conn) use ($loop) { $conn->pipe(new Stream(STDOUT, $loop)); $conn->write("Hello World!\n"); }); $client->connect(); $loop->run();