Autobahn-js failes to connect to Ratchet Server (Wamp)

416 Views Asked by At

I've already checked plenty of questions and tutorials and I'm following the official documentation from socketme portal. I'm running this on XAMPP/Localhost.

Websocket works, when I'm not using the WAMP interface. Otherwise, it fails to connect and doesn't state any reason.

Error is: "app.js:6200 WebSocket connection to 'ws://localhost:8080/socket' failed: connection closed unreachable"

Server

$server = new \Ratchet\App('localhost', 8080);
$server->route('/socket', new WebSocketHandler, array('*'));
$server->run();

WebSocketHandler is a basic implementation of WampServerInterface and only includes the abstracted methods without any change.

On the client side, I'm doing the following to try a connection via autobahn-js:

           var connection = new Autobahn.Connection({

            transports: [{
                type: 'websocket',
                port: 8080,
                host: 'localhost',
                url: 'ws://localhost:8080/socket'
            }],
            realm: 'realm1'
        });

        connection.onopen = function(session) {
            app.content = app.content + `connected!`
        };

        connection.onclose = function(reason, details) {
            app.content = app.content + `onclose!`
        }

        connection.open();

I've done something wrong in this implementation, but I can't figure it out. I've tried avoiding the ->route approach and using the following vanilla approach:

$server = IoServer::factory(
    new HttpServer(
        new WsServer(
            new WampServer(
              new WebSocketHandler()
              )
        )
    ),
    8080
);

But, it didn't work.

Any help is much appreciated.

1

There are 1 best solutions below

0
Jaeger On BEST ANSWER

You need Autobahn.js 0.8.2 to connect it to Ratchet (WAMP v1) and it's a pretty old implementation and also ab 0.8.2 is extremely old.

You should navigate your work to Thruway. I tried doing it, but I couldn't find any custom implementation of Thruway RatcherRouter (onMessage, onOpen, etc.), therefore, I decided to do my own (pretty bad) implementation of Ratchet.

TL;DR: Switch to Thruway.