43 lines
853 B
PHP
43 lines
853 B
PHP
<?php
|
|
|
|
require_once(__DIR__ . '/RpcCommon.php');
|
|
|
|
if (!isset($g_zmqcontext)) {
|
|
$g_zmqcontext = new ZMQContext();
|
|
}
|
|
|
|
class PublishSocket extends RpcCommon {
|
|
|
|
private $__socket;
|
|
|
|
function __construct(&$test, $uri, $connect = false) {
|
|
parent::__construct($test);
|
|
global $g_zmqcontext;
|
|
|
|
$this->__test = $test;
|
|
$this->__socket = $g_zmqcontext->getSocket(ZMQ::SOCKET_PUB);
|
|
if ($connect) {
|
|
$this->__socket->connect($uri);
|
|
sleep(3);
|
|
} else
|
|
{
|
|
$this->__socket->bind($uri);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* ..
|
|
*/
|
|
function send($data, $result = null) {
|
|
if (is_string($data)) {
|
|
$ret = $this->__socket->send($data);
|
|
} elseif (is_array($data)) {
|
|
$ret = $this->__socket->send(json_encode($data));
|
|
} else {
|
|
$this->__test->failure("RPC message is not a valid reply");
|
|
var_dump($data);
|
|
}
|
|
$this->_test->equal($this->__socket, $ret);
|
|
}
|
|
}
|