React / ZMQ / Ratchet - resposta do servidor Websocket
Atualmente, tenho um servidor de soquete da Web executando e trabalhando com o Ratchet PHP. Não estou no estágio em que quero que scripts externos se comuniquem com meu servidor. Posso enviar dados com êxito usando o ZMQ:
push.php$json = ['name' => 'Joe Bloggs'];
$context = new ZMQContext();
$socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'Push Notification');
$socket->connect("tcp://localhost:5555");
$socket->send(json_encode($json));
Em seguida, no script do meu servidor da web, posso enviar isso para um método (onNewPush
) para fazer algo quando o arquivo push.php for executado (executado?):
...
$push = $context->getSocket(ZMQ::SOCKET_PULL);
$push->bind('tcp://127.0.0.1:5555');
$push->on('Push Notification', array($pusher, 'onNewPush'));
...
Portanto, isso funciona bem, mas estou tendo problemas para tentar receber uma resposta de volta. Estou tentando algo como:
pull.php$context = new ZMQContext();
$socket = $context->getSocket(ZMQ::SOCKET_REQ, 'Pull Notification');
$socket->connect("tcp://localhost:5554");
$socket->send('data');
echo $socket->recv();
Então, no meu script de servidor:
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:5554');
$pull->on('message', array($pusher, 'onPull'));
Minhas$pusher
A variável carrega meu arquivo, que implementa algumas interfaces de catraca. Mas basicamente estou retornando uma string:
public function onPull()
{
return "some data";
}
Ao executarpull.php
Eu recebo o erro:
Fatal error: Uncaught exception 'ZMQSocketException' with message 'Failed to receive message: Not supported' in websockets\pull.php:9 Stack trace: #0 websockets\pull.php(9): ZMQSocket->recv() #1 {main} thrown in websockets\pull.php on line 9
Alguem sabe por quê?
Também qual a importância do segundo parâmetro nogetSocket()
ter? Parece uma string que nunca é usada novamente.
Felicidades
ATUALIZADA