5

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?

Jimut
  • 195
  • 3
  • 13
  • Did you find a solution for this problem? I'm having the same issue and I don't find anything – Rey Aug 25 '17 at 20:16

3 Answers3

2
$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');
Pankaj Kumar
  • 129
  • 1
  • 12
1

I later found out using other ports are not allowed on a shared server.

If you are on a private server with a ssh access, you can try MarshallOfSound's solution.

Or if you just need the websocket as a service you can use something like Pusher.

Jimut
  • 195
  • 3
  • 13
0

It means that nother process is running on port 8080. Probably a webserver of some kind.

You can find out what is running with the command

lsof -i :8000

You can either stop the process already using the port. Or run Ratchet on a different port.

MarshallOfSound
  • 2,629
  • 1
  • 20
  • 26
  • I tried it with many other ports, but it still gave same error. Do I have to give the ip address of the server in place of '0.0.0.0'. (I am confused, nothings' working) – Jimut Sep 27 '15 at 17:34