Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Ratchet remotely or on a server?

Everything works fine on my local machine on XAMPP. But after I uploaded the files to a server, it gives a error like this...

Fatal error: Uncaught exception 'React\Socket\ConnectionException' with message 'Could not bind to tcp://0.0.0.0:8080: Address already in use' in 
/home/sites/jemaottest.com/public_html/websocket/vendor/react/socket/src/Server.php:29 Stack trace: #0 
/home/sites/jemaottest.com/public_html/websocket/vendor/cboden/ratchet/src/Ratchet/Server/IoServer.php(70): React\Socket\Server->listen(8080, '0.0.0.0') #1 
/home/sites/jemaottest.com/public_html/websocket/bin/chat-server.php(17): Ratchet\Server\IoServer::factory(Object(Ratchet\Http\HttpServer), 8080, '0.0.0.0') #2 {main} thrown in 
/home/sites/jemaottest.com/public_html/websocket/vendor/react/socket/src/Server.php on line 29

when I run the chat-server.php file.

I found out something on the troubleshooting page of Ratchet which says,

If you want to open Ratchet up (not behind a proxy) set the third parameter of App to '0.0.0.0'.

I tried that but it didn't work,

<?php 
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use MyApp\Chat;

require dirname(__DIR__).'/vendor/autoload.php';

$server = IoServer::factory(
    new HttpServer(
        new WsServer(
            new Chat()
        )
    ),
    8080,
    '0.0.0.0'
);

$server->run();  
?>

it still gave the same error.

What should I do now?

like image 630
Jimut Avatar asked Oct 19 '22 01:10

Jimut


1 Answers

$server = IoServer::factory(
new HttpServer(
    new WsServer(
        new Chat()
    )
),
8282

);

Just Change the port and try.. mine is works fine after changing my port. And also don't forget to change the port in your port in websocket javascript class too.

var conn = new WebSocket('ws://yourdomain.com:8282');
like image 70
Pankaj Kumar Avatar answered Oct 29 '22 03:10

Pankaj Kumar