Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!