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

179
Visualizações
Using ws and wss simultaneously

I am trying to get both ws and wss working, on one WebSocket server.

This is what I currently have, only wss

var WebSocket = require('ws');
var https = require('https');

var privateKey = fs.readFileSync('cert/key.key');
var certificate = fs.readFileSync('cert/cert.crt');

var httpsServer = https.createServer({
    ca: ca,
    key: privateKey,
    cert: certificate
}, this.app);

var options = {
    server: httpsServer, 
    perMessageDeflate: false,
    maxPayload: 4096
};

var wss = new WebSocket.Server(options);

I know using Socket.io it is really easy, you can just do io.attach(httpServer) and io.attach(httpsServer).

var httpServer = http.createServer(this.app);
var httpsServer = https.createServer({
    key: privateKey,
    cert: certificate
}, this.app);

httpServer.listen(3002, function(){
    console.log('httpServer listening on port 3002');
});

httpsServer.listen(3003, function(){
    console.log('httpsServer listening on port 3003');
});

this.io = new ioServer();
this.io.attach(httpServer);
this.io.attach(httpsServer);

Is this even possible, using this WebSocket library?

over 4 years ago · Santiago Trujillo
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