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

374
Visualizações
Socket.io chat application working only on localhost

I'm completely new to web sockets and javascript. I'm trying to create a chat application using javascript and socket.io. It works on localhost (using "npm start" command line).

My question is: how can I access it from any other PC and use it like a real chat application?

I have the following error when I don't access it on localhost:

error

How can I host it for free and access it from anywhere? Can someone provide me an example of a socket.io chat application and step-by-step instructions?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It does not work because if you are accessing to your website not from localhost, your hostname will not be the server address. So, in your var socket = io(); you can specify the url that the user is accessing your website from.

Like this:

// get the url
let url = window.location.href.split("/");
url = url[0] + "//" + url[2];

const socket = io(url);
about 4 years ago · Juan Pablo Isaza Relatório
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