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

142
Visualizações
Localhost chat system wont connect through other computer

I have my localhost game and chat system that works when i use it on my laptop through google chrome and another on firefox. you can message and see each others messages with your names.

However, when i go to connect using my desktop, it doesnt work. Can you please help me figure out why it wont connect?

Here is my code:

script.js:

const socket = io.connect()
const messageContainer = document.getElementById('message-container')
const messageForm = document.getElementById('send-container')
const messageInput = document.getElementById('message-input')

const name = sessionStorage.getItem("chatUsername");

appendMessage('You joined')
socket.emit('new-user', name)

socket.on('chat-message', data => {
  appendMessage(`${data.name}: ${data.message}`)
})

socket.on('user-connected', name => {
  appendMessage(`${name} connected`)
})

socket.on('user-disconnected', name => {
  appendMessage(`${name} disconnected`)
})

messageForm.addEventListener('submit', e => {
  e.preventDefault()
  const message = messageInput.value
  appendMessage(`You: ${message}`)
  socket.emit('send-chat-message', message)
  messageInput.value = ''
})

function appendMessage(message) {
  const messageElement = document.createElement('div')
  messageElement.innerText = message
  messageContainer.append(messageElement)
}

Server.js

const io = require("socket.io")(3000, {
  cors: {
    origin: "*",
  },
});
const users = {}

io.on('connection', socket => {
  socket.on('new-user', name => {
    users[socket.id] = name
    //socket.broadcast.emit('user-connected', name)
  })
  socket.on('send-chat-message', message => {
    socket.broadcast.emit('chat-message', { message: message, name: users[socket.id] })
  })
  socket.on('disconnect', () => {
    //socket.broadcast.emit('user-disconnected', users[socket.id])
    delete users[socket.id]
  })
})

I get this error on my desktop when trying to connect through:

failed to  http://192.***.*.**/socket.io/socket.io.js load resources the server responded with a status of 404 (Not found)

and..

uncaught ReferenceError: io is not defined

** are there to cover my ip.

I am using my ip address to connect to my locahost computer ( laptop) from my desktop for playing my game. If you need to update code then please do. I'm super stumped on this and Im not sure why its not working. ( p.s im super new to this whole thing)

Thanks in advance!

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