我有一个用棘轮编写的websocket服务器,当它绑定到127.0.0.1:5555时效果很好。但是,我需要在同一台机器上运行另一个脚本实例,所以我尝试创建另一个绑定到不同端口的实例,但是客户端可以连接并订阅一个主题,但是他们没有收到任何数据应该被推到连接上。我尝试了很多不同的端口甚至不同的环回(127.0.0.1/8),但似乎唯一有效的是127.0.0.1:5555。如何让其他端口或环回工作?
实例#1 ,有效:
// Listen for the web server to make a ZeroMQ push after an ajax request
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($pusher, 'onUpdate'));
// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server($loop);
$webSock->listen(8080, '0.0.0.0'); // Binding to 0.0.0.0 means remotes can connect
$webServer = new Ratchet\Server\IoServer(
new Ratchet\Http\HttpServer(
new Ratchet\WebSocket\WsServer(
new Ratchet\Wamp\WampServer(
$pusher
)
)
), $webSock
);
$loop->run();
实例#2 ,绑定到另一个无效的端口:
// Listen for the web server to make a ZeroMQ push after an ajax request
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('127.0.0.1:4444'); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($pusher, 'onUpdate'));
// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server($loop);
$webSock->listen(9090, '0.0.0.0'); // Binding to 0.0.0.0 means remotes can connect
$webServer = new Ratchet\Server\IoServer(
new Ratchet\Http\HttpServer(
new Ratchet\WebSocket\WsServer(
new Ratchet\Wamp\WampServer(
$pusher
)
)
), $webSock
);
$loop->run();