WebSocket Server works but not WampServer

259 views
Skip to first unread message

Saurabh Machave

unread,
Oct 25, 2015, 12:08:51 AM10/25/15
to Ratchet
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

Saurabh Machave

unread,
Oct 25, 2015, 8:51:45 AM10/25/15
to Ratchet
I realized what went wrong. I was trying WAMP v2 clients with Ratchet. I tested a little with Autobahn for WAMP v1 and it worked!
Reply all
Reply to author
Forward
0 new messages