Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

347
Visualizações
WebSocket connection to failed:

After looking at too many stackeoverflow question i could not find any solution which solve my problem,

i develop application with ratchet websocket.me which is working in my local machine fine with WS//:localhost:8080 but its not working on live (VPS) server here below is the server configuration and requirements,

I am not sure what i am doing wrong look at below code snippet

SERVER CONFIGURATION

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName kosm.online
    ServerAlias www.kosm.online
    ServerAdmin webmaster@kosm.online
    DocumentRoot "/var/www/kosm"
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    ProxyPreserveHost On
  ProxyPass /wss2/ wss://kosm.online:8080


Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/kosm.online/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/kosm.online/privkey.pem
</VirtualHost>
</IfModule>

CLIENT SITE WEBSOCKET JAVASCRIPT

var token = document.getElementById('userToken').value;
var socket = new WebSocket('wss://kosm.online:8080?token=' + token);
    socket.onclose = function(event) {
        console.log('connection close');
    };
    socket.onopen = function(event) {
        console.log("Connection established!");
        // socket.send('Hello Me!');
    };

HERE IS WEBSOCKET SERVER

require dirname( __FILE__ ) . '/vendor/autoload.php';
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use MyApp\Socket;

    $server = IoServer::factory(
        new HttpServer(
            new WsServer(
                new Socket()
            )
        ),
        8080
    );
    
    $server->run(); 

HERE IS COMPOSER.JSON

{
    "autoload": {
        "psr-4": {
            "MyApp\\": "app"
        }
    },
    "require": {
        "cboden/ratchet": "^0.4.3"
    }
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda