'Ratchet PHP with ZMQ and OriginCheck - am I doing it wrong?
Please consider the following Ratchet PHP WS server creation. It listens for WS client connections as well as messages from ZMQ. Upon reception of ZMQ messages, it forwards the info to some client WS connections based on business logic behind.
I only use an insecure websocket here as I use Apache to reverse-proxy for SSL. The problem is that it works perfectly when accessed from a browser, but when accessed by a command line WS client, every once in a while I get the following warning, at which point the socket closes:
It didn't happen until I added the Origin checking mechanism. Should I stick to Ratchet's origin checking, or use some other mechanism?
My server creation code (is it even correct?):
// React loop
$loop = React\EventLoop\Factory::create();
$pusher = new MyApp\Api;
// ZMQ
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind("tcp://127.0.0.1:7777");
$pull->on('message', array($pusher, 'onZMQ'));
// WS
$webSock_insecure = new React\Socket\Server(
"127.0.0.1:8080",
$loop
);
$wsSrv = new Ratchet\WebSocket\WsServer($pusher);
$wsSrv->enableKeepAlive($loop, 1);
$checkedWsSrv = new Ratchet\Http\OriginCheck($wsSrv, ['localhost']);
$checkedWsSrv->allowedOrigins[] = '';
$checkedWsSrv->allowedOrigins[] = 'mysite.com';
$webServer_insecure = new Ratchet\Server\IoServer(
new Ratchet\Http\HttpServer($checkedWsSrv),
$webSock_insecure
);
$loop->run();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
