can't connect online to server with Rachet (JS, PHP)

534 views Asked by At

The site works perfectly fine on local instance though when I try to run it on live server I get the following error

WebSocket connection to 'ws://localhost:8888/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

I've opened the port on fire wall and tested it like this -

telnet 127.0.0.1 8888
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

what else should I check? BTW just making sure, when I run the site online should I still use localhost as the address or the site ip ? (I've tried both, both times got the same error)

1

There are 1 answers

0
MarshallOfSound On

When you run the socket online you should use this code to start the socket

$app = new Ratchet\App(__SERVER_HOSTNAME__, 8888, '0.0.0.0');

Where the constant __SERVER_HOSTNAME__ is the domain name your WebSocket is running on.

Then in javascript you would connect to
ws://<?php echo __SERVER_HOSTNAME__; ?>:8888