How to use WSS with HTTPS using Ratchet and Apache?

100 Views Asked by At

I have made a website using PHP with Apache, and using Ratchet to work with Weksockets that I host on my Raspberry Pi, which is running Raspbian GNU/Linux 11 (bullseye). Once I have set up and SSL certification with Cerbot, I tried, and see that I have to use WSS instead of WS. I have those files : app.js :

var hostname = window.location.hostname;
var port = 8001;
var ws = new WebSocket('ws://' + hostname + ':' + port + "?id_class=" + id + "&id_user=" + id_user + "&chap_name=" + chap_name + "");

and the server.php file :

<?php

require __DIR__ . '/../vendor/autoload.php';

use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

require "EditorServer.php";
require __DIR__ . "/../vendor/autoload.php";

$port = isset($_SERVER["CHAT_SERVER_PORT"]) ? $_SERVER["CHAT_SERVER_PORT"] : 8001;
$bindAddr = isset($_SERVER['CHAT_BIND_ADDR']) ? $_SERVER['CHAT_BIND_ADDR'] : '0.0.0.0';


$file = "lecon.txt";

$server = IoServer::factory(
    new HttpServer(
        new WsServer(
            new MyApp\EditorServer($file)
        )
    ),
    $port, $bindAddr
);

printf("Websocket Editor server running on %s:%s.\n--\n", $bindAddr, $port);
$server->run();

So I tried to put "wss" instead of "ws" in the app.Js file, but is said in the Google Chrome console that "app.js:14 WebSocket connection to 'wss://MYSITE:8001/?id_class=1&id_user=6&chap_name=' failed:". I check many tutorials, but each time it didn't work. So do you know ho to make it work ?

0

There are 0 best solutions below