Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REQ/REP seems not working #59

Open
Nek- opened this issue Mar 28, 2019 · 0 comments
Open

REQ/REP seems not working #59

Nek- opened this issue Mar 28, 2019 · 0 comments

Comments

@Nek-
Copy link

Nek- commented Mar 28, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant