concerto/comms

Library for Inter-Process Communications using Unix domain sockets.

Installs: 94

Dependents: 2

Stars: 23

Watchers: 1

Forks: 3

Language: PHP

v0.8 2014-08-15 22:50 UTC

README

Library for Inter-Process Communications using Unix domain sockets.

Build Status

Install

The recommended way to install Comms is through composer.

{
    "require": {
        "concerto/comms": "0.*"
    }
}

Usage

Server

use Concerto\Comms\Server;
use React\EventLoop\Factory;

$loop = Factory::create();
$comms = new Server($loop, 'unix://' . __DIR__ . '/test.ipc');

$comms->on('join', function() {
    echo "Client joined.\n";
});

$comms->on('part', function() {
    echo "Client exited.\n";
});

$comms->on('message', function($message) use ($comms) {
    echo "Client said: $message\n";

    $comms->send('...');
});

$comms->listen();
$loop->run();

Client

use Concerto\Comms\Client;
use React\EventLoop\Factory;

$loop = Factory::create();
$comms = new Client($loop, 'unix://' . __DIR__ . '/test.ipc');

$comms->on('join', function() {
    echo "Server joined.\n";
});

$comms->on('part', function() {
    echo "Server exited.\n";
    exit;
});

$comms->on('message', function($data) {
    echo "Server said: $data\n";
});

$comms->send('...');

$comms->connect();
$loop->run();