SOCKET_PUSH没有使用ZMQContext发送任何内容? [被防火墙阻挡......]

时间:2018-04-04 05:23:15

标签: php zeromq ratchet

我正在尝试使用Ratchet / ZMQ Socket编程的本教程: http://socketo.me/docs/push

通过一些自定义来学习更多关于它的信息。

服务器本身运行正常,前端html之间的连接似乎正在连接。但我无法想象发送消息到服务器的PHP文件。

以下代码:

SENDER.PHP

ab.debug(true,true);
var conn = new ab.Session('ws://localhost:8080',
        function() {
            conn.subscribe('kittensCategory', function(data) {
                // This is where you would add the new article to the DOM (beyond the scope of this tutorial)
                console.log("New data available: ",data);
            });
        },
        function() {
            console.warn('WebSocket connection closed');
        },
        {'skipSubprotocolCheck': true}
);

上面的代码就是我遇到的问题。当我在命令行中运行代码时

use Models\SCSTRealtimeSubsObject; // The event loop that will keep on triggering $loop = React\EventLoop\Factory::create(); // Our custom pusher that will do the logic, $loop is optional $pusher = new SCSTRealtimeSubsObject; // 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); //Binding to itself means the client can only connect to itself $pull->bind("tcp://127.0.0.1:5555"); //On a 'message' event, pass the data to the myMessageHandler method of the MyPusherClass $pull->on('message', array($pusher, 'customAction')); // Set up our WebSocket server for clients wanting real-time updates $webSock = new React\Socket\Server('0.0.0.0:8080', $loop); // 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();

服务器应该至少显示一些反馈,但它不会给我任何东西。而sender.php就退出了。 我试图弄清楚我失踪了什么。至少前面的html位有效。 如何让sender.php发送消息?任何建议/建议/帮助将不胜感激。

以下是我的其余代码:

的index.html

当我从构造函数中获取消息时,此html文件正在连接。

class SCSTRealtimeSubsObject implements WampServerInterface {

    public function __construct() {
        echo "Constructor call. \n";
    }
    public function customAction($msg){ // Message from the onMessage
        echo "There was a message: $msg";
    }
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    //                  WampServerInterface Implementations
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    public function onOpen(ConnectionInterface $conn) {
        echo "New connection! ({$conn->resourceId}) \n";
    }
    public function onClose(ConnectionInterface $conn) {
        // The connection is closed, remove it, as we can no longer send it messages
        echo "Connection {$conn->resourceId} has disconnected \n";
    }
    public function onError(ConnectionInterface $conn, \Exception $e) {
        echo "There is an error ". $e->getMessage();
    }
    public function onSubscribe(ConnectionInterface $conn, $topic) {
        echo "New subscriber : $topic \n";
    }
    public function onUnSubscribe(ConnectionInterface $conn, $topic) {
        echo "Unsubscribed : $topic \n";
    }
    public function onCall(ConnectionInterface $conn, $id, $topic, array $params) {
        // In this application if clients send data it's because the user hacked around in console
        $conn->callError($id, $topic, 'You are not allowed to make calls')->close();
    }
    public function onPublish(ConnectionInterface $conn, $topic, $event, array $exclude, array $eligible) {
        // In this application if clients send data it's because the user hacked around in console
        echo "Published $topic. \n";
        $conn->close();
    }
}

SERVER.PHP

ARCH=arm

PUSHER.PHP

CROSS_COMPILE=<path to toolchain>

2 个答案:

答案 0 :(得分:2)

终于找到了答案。我忘了把我的开发服务器放在Windows上。

在我的情况下,php cli被Windows防火墙阻止访问任何网络和端口。

要解决此问题,请转到控制面板 - &gt; Windows防火墙。寻找入站CLI这很可能是PhP exe。允许访问网络,这应该可以解决问题。

答案 1 :(得分:0)

嘿,我的PHP可以正常工作,但是当我执行ajax调用来执行文件时,它挂起并失败。你有同样的问题吗?我也在Windows上。