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?
$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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With