I'm trying to use Ratchet to create WebSockets
in PHP
on a site I own. When I ran the tests ( localhost
) everything worked perfectly, but when I try to put it online, it does not run the connection. Reading more on the subject, I saw that it would be necessary to change ip
to be the server's - or use the correct reference. Which led me to this final code:
var socket = new WebSocket('ws://meusite.com.br:8000');
But when I access the site, after a while, I get this message:
failed: Error in connection establishment: net :: ERR_CONNECTION_TIMED_OUT
The server file has this code:
require __DIR__ .'/../vendor/autoload.php';
use Ratchet\Server\IoServer;
use Ratchet\http\HttpServer;
use Ratchet\WebSocket\WsServer;
$server = IoServer::factory(
new HttpServer(
new WsServer(
new Chat()
)
), 2000, '0.0.0.0'
);
$server->run();
I'm using composer
also for the Ratchet
package management.
I do not know what might be happening to not have the connection or what I let pass, but this process is not working online, only in localhost
.
Editing the question, and already adding the response to the comment, I have access SSH
yes, even when I try to start the script as done in localhost
php bin/server.php
The SSH
displays the following error:
Fatal error: Class 'Ratchet \ http \ HttpServer' not found in /bin/server.php on line 10
Note : The final application is not going to be a chat, I'm doing this just for following a tutorial. The goal is to only exchange messages to inform you that a new request has been made, or that a new service order has arrived, etc.