concerto/comms

使用 Unix 域套接字进行进程间通信的库。

维护者

详细信息

github.com/usebeagle/comms

安装: 647

依赖项: 2

建议者: 0

安全: 0

星标: 28

关注者: 0

分支: 2

类型:concerto-component

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

This package is not auto-updated.

Last update: 2020-08-07 18:31:41 UTC


README

使用 Unix 域套接字进行进程间通信的库。

Build Status

安装

安装 Comms 的推荐方法是 通过 composer

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

使用方法

服务器

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

客户端

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