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.

Maintainers

Details

github.com/usebeagle/sockets

Installs: 660

Dependents: 1

Suggesters: 0

Security: 0

Stars: 3

Watchers: 1

Forks: 0

Type:concerto-component

v0.3 2014-07-01 09:09 UTC

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.

Build Status

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();