PHP WebSocket connection issue over SSL

286 Views Asked by At

I have some issues connecting a web socket in PHP.

I'm using this repo: https://github.com/ghedipunk/PHP-Websockets

If I run in localhost, everything is fine, the service is on. But when I move to the server is where everything comes down. I have an AWS Lightsail hosting, my domain has SSL, and I'm using Plesk.

In my AWS panel, I opened port 8000 By console I added this line in /etc/apache2/mods-enabled/proxy_wstunnel.load:

ProxyPass "/chat/"  "wss://localhost:8000/"

and also

ProxyPass "/chat/"  "wss://socket.injectxgames.io:8000/"

Then sudo service apache2 restart

Then I enter the console to execute the PHP file with the service and I have this:

Server started
Listening on: localhost:8000
Master socket: Resource id #6

Everything is just fine, but JS is where I can't able to connect.

function init() {
    // Apuntar a la IP/Puerto configurado en el contructor del WebServerSocket, que es donde está escuchando el socket.
    var host = "wss://socket.injectxgames.io:8000"; 
    try {
        socket = new WebSocket(host);
        log('WebSocket - status '+socket.readyState);
        socket.onopen    = function(msg) { 
                               log("Welcome - status "+this.readyState); 
                           };
        socket.onmessage = function(msg) { 
                               log("Received: "+msg.data); 
                           };
        socket.onclose   = function(msg) { 
                               log("Disconnected - status "+this.readyState); 
                           };
    }
    catch(ex){ 
        log(ex); 
    }
    $("msg").focus();
}

Even I have tried as www.injectxgames.io/chat and nothing, I have this error:

"WebSocket connection to 'wss://www.injectxgames.io:8000/' failed"

What could be missing?

0

There are 0 best solutions below