Hello,
First, I tried Ratchet using a WsServer and it worked perfectly. Then I was trying the WampServer but that did not work as expected. The connection opened, but the publish did not work. I tried with Autobahn.js and Wampy.js with no luck. With Autobahn, the connection kept on opening and closing rapidly and with Wampy.js it just stayed open and nothing happened.
Here is my server configuration:
<?php
require 'vendor/autoload.php';
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use Ratchet\Wamp\WampServer;
use Ratchet\Session\SessionProvider;
use Symfony\Component\HttpFoundation\Session\Storage\Handler;
class PubSub implements Ratchet\Wamp\WampServerInterface {
public function onPublish( Ratchet\ConnectionInterface $conn, $topic, $event,
array $exclude, array $eligible ) {
echo "published\n";
}
public function onCall( Ratchet\ConnectionInterface $conn, $id, $topic, array $params ) {
echo "called\n";
}
public function onSubscribe( Ratchet\ConnectionInterface $conn, $topic ) {}
public function onUnSubscribe( Ratchet\ConnectionInterface $conn, $topic ) {}
public function onOpen(Ratchet\ConnectionInterface $conn) {
echo "opened\n";
}
public function onClose(Ratchet\ConnectionInterface $conn) {
echo "closed\n";
}
public function onError(Ratchet\ConnectionInterface $conn, \Exception $e) {
echo "error\n";
}
}
$memcache = new Memcached;
$memcache->addServer('localhost', 30024);
$server = IoServer::factory(
new HttpServer(
new WsServer(
new SessionProvider(
new WampServer (
new PubSub()
), new Handler\MemcachedSessionHandler($memcache)
)
)
),
30024
);
$server->run();
?>
As for the client Javascript, I used the sample scripts on their github pages.
Regards,
Saurabh