Skip to content

REQ/REP seems not working #59

@Nek-

Description

@Nek-

Hello,

I'm trying to use REQ/REP with reactphp-zmq. While it works properly with the PHP extension, it seems to have some issues.

$loop = React\EventLoop\Factory::create();

$context = new React\ZMQ\Context($loop);

$requester = $context->getSocket(ZMQ::SOCKET_REQ);
$requester->connect('tcp://127.0.0.1:5555');

$i = 0;
$loop->addPeriodicTimer(1, function () use (&$i, $requester) {
    $i++;
    echo "(out) -> $i\n";
    $requester->send($i);
    $reply = $requester->recv();
    echo "(in) <- $reply\n";
});

$loop->run();

Here is the output:

$ php test.php
-> 1
PHP Fatal error:  Uncaught ZMQSocketException: Failed to receive message: Operation cannot be accomplished in current state in /var/www/apps/cadi-back/vendor/react/zmq/src/SocketWrapper.php:171
Stack trace:
#0 [internal function]: ZMQSocket->recv()
#1 /var/www/apps/cadi-back/vendor/react/zmq/src/SocketWrapper.php(171): call_user_func_array(Array, Array)
#2 /var/www/apps/cadi-back/test.php(19): React\ZMQ\SocketWrapper->__call('recv', Array)
#3 /var/www/apps/cadi-back/vendor/react/event-loop/src/Timer/Timers.php(96): {closure}(Object(React\EventLoop\Timer\Timer))
#4 /var/www/apps/cadi-back/vendor/react/event-loop/src/StreamSelectLoop.php(183): React\EventLoop\Timer\Timers->tick()
#5 /var/www/apps/cadi-back/test.php(23): React\EventLoop\StreamSelectLoop->run()
#6 {main}
  thrown in /var/www/apps/cadi-back/vendor/react/zmq/src/SocketWrapper.php on line 171

I understand that this code is not optimal considering I send each second no matter if the reply occured (while it must be according to zmq protocol). But here the issue is about ->recv() not working in "current state" (which should be the good one).

[edit] this is probably due to the buffer that delays the send to "later" while the recv is not delayed. Not a trivial problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions