I try to write ratchet chat webAplication. it works well on xampp but it doesn't work on server. I run server.php from ssh and get this error when open the site: WebSocket connection to 'ws://farahaniacademy.com:8080/' failed.
here is my code:
server.php:
<?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
);
$server->run();
?>
index.php:
<script>
const conn = new WebSocket('ws://farahaniacademy.com:8080');
conn.onopen = function(e)
{
console.log("Connection established!");
};
</script>
it solved. the problem was the firewall of server. when I allow the port everything works fine.