I have a problem with a websocket server. It’s also my first time with this tech.
I’m using :
- Apache
- Ratchet (PHP)
- SSL (HTTPS on 443 as usual)
I was using this source to make my configuration (it’s in French).
But I can’t connect to my websocket from client with js. I’m still getting this error :
WebSocket connection to ‘wss://server_name.fr/ws/game’ failed
Here is my config file for my site :
<VirtualHost server_name.fr:443>
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/server_name/public/
<Directory /var/www/html/server_name/>
AllowOverride All
</Directory>
<Location "/ws/game">
ProxyPass wss://localhost:1176
ProxyPassReverse wss://localhost:1176
</Location>
The JS :
var conn = new WebSocket('wss://server_name.fr/ws/game');
conn.onopen = function(e) {
console.log("Connection established!");
};
conn.onmessage = function(e) {
console.log(e.data);
};
The PHP Server that I’m runnning on port 1176 (Almost exactly the exemple):
<?php require __DIR__ . '/vendor/autoload.php';
use RatchetServerIoServer;
use RatchetHttpHttpServer;
use RatchetWebSocketWsServer;
use RatchetMessageComponentInterface;
use RatchetConnectionInterface;
define('APP_PORT', 1176);
class ServerGame implements MessageComponentInterface
{
protected $lobby;
protected $rooms;
protected $client_in_room;
public function __construct()
{
$this->lobby = array();
}
public function onOpen(ConnectionInterface $conn)
{
}
public function onMessage(ConnectionInterface $conn, $msg)
{
}
public function onClose(ConnectionInterface $conn)
{
}
public function onError(ConnectionInterface $conn, Exception $e)
{
}
}
$server = IoServer::factory(
new HttpServer(
new WsServer(
new ServerGame()
)
),
APP_PORT
);
echo "Server created on port " . APP_PORT . "nn";
$server->run();
Thanks for your help !