Ejemplo n.º 1
0
#!/usr/bin/env php
<?php 
require __DIR__ . '/../vendor/autoload.php';
use App\System\Clock;
use App\System\Daemon;
$transport = 'tcp';
$address = '127.0.0.1';
$port = '5881';
$daemon = new Daemon(__DIR__ . '/../pids/clockd' . '.pid');
$daemon->init();
$clock = new Clock($transport, $address, $port);
try {
    $clock->open()->connect();
} catch (Exception $exc) {
    echo $exc->getTraceAsString();
    exit;
}
$clock->run();
Ejemplo n.º 2
0
#!/usr/bin/env php
<?php 
require __DIR__ . '/../vendor/autoload.php';
use React\ZMQ\Context;
//use React\EventLoop\Factory;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use App\System\ClockServer;
use App\System\Daemon;
$daemon = new Daemon(__DIR__ . '/../pids/clock' . '.pid');
$daemon->smallInit();
$transport = 'tcp';
$address = '127.0.0.1';
$port = '5881';
//$loop = Factory::create(); ???
$clock = new ClockServer();
$server = IoServer::factory(new HttpServer(new WsServer($clock)), 8080);
$context = new Context($server->loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind($transport . "://" . $address . ":" . $port);
// Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($clock, 'onClockMessage'));
$server->run();