0

The title says it all.Here's my code:

(Shell script)
$loop   = React\EventLoop\Factory::create();
$pusher = new MyApp\Chat;

//Receiving IPC messages:
$socket = new React\Socket\Server($loop);
$socket->on('connection', function ($conn) {
    $pusher = new MyApp\Chat;
    echo date('H:i:s'). "!!IPC Connection opened!!\n";

    $conn->on('data', array($pusher, 'onUpdate'));
});

$socket->listen(1337, '127.0.0.1'); //Binding to our IP so remotes can't connect.

echo "%%% IPC listener started succesfully. %%%\n%%%\n";

// WebSocket server:
//here the code is identical to that on the Ratchet 'push-server' tutorial

...and the "onUpdate" function...

public function onUpdate($entry)
{
    echo(date('H:i:s'). ": !<<---IPC Data Received.DATA:::". $entry. ":::--->>!\n");
    $topic = 'Prime_mover';
    $topic->broadcast($entry);
}

...the "onPublish" function:

public function onPublish(Conn $conn, $topic, $event, array $exclude, array $eligible )
{
    echo $topic. "\n";
    //echo implode(array_keys($topic)). "\n";
    $channel = $topic->getId();

    if($topic->broadcast($event))
    {
        echo(date('H:i:s') . ": ***A client has published ###" . 
            implode('',      $event) . "### to (((". $channel. ")))***\n");
    } else {
        echo(date('H:i:s'). ": !!<--An error occured during publish-->!!\n");
    }
}

The client code is trivial.

I am sure the bug, if any (I've been at this for about 10 hours), does not reside there.

I confirm via the console that indeed the browser is subscribed to "Prime_mover". This also shows up on the CLI. In addition, I have put a button that publishes to this channel, via the "onPublish" function. This works.

As can be seen above, I am not using ZeroiMQ for IPC because I am developing on a windows machine, on PHP 5. AFAIK, there exists no working ZeroMQ bindings for PHP5.

I resorted to using bare sockets. They work just as beautifully, and I can see on the CLI that the messages do get to this particular script.

The "onUpdate" function does get called, confirmed, again, via the CLI.

I had previously tried using the URL "http:\example.com\Prime_mover", when it did not work, out of desperation, I tried the string "Prime_mover". You're probably shaking your head right now-I know, does't work that way.

I have tried to use $topica as an array too, does not work.I guess the most important question here is, what kind of object is $topic, why won't a simple string work in it's place?Am I missing something here?How is it "constructed" correctly?

4

1 に答える 1