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');
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.
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.
来源:https://stackoverflow.com/questions/32779364/how-to-run-ratchet-remotely-or-on-a-server