marczking marczking - 1 year ago 77
Node.js Question

Socket connection not recognising all clients/connections

So far sockets is working as expected. On my server I have:

const io = require('')(1923);

// after an action
io.sockets.emit('items', data);

Then on the client side:

const socket = io.connect('http://localhost:1923');
socket.on('items', (items) => {
// do stuff with items

Now this is working nicely when I'm on my own machine. As soon as different devices open the site it only updates on the browsers on my computer.


  • Firefox has the site open

  • Chrome too


  • Site is open on Chrome for mobile

Now after an action takes place, only the sites on the computer gets updated and not my new device. Checking the connections it also only recognises
clientsCount: 2
. (instead of 3)

The site is open on three separate browsers. What am I doing wrong for this to be happening?

(sidenote: I've tried the same with a second computer, it's not specific to the mobile device.)

Answer Source

Making my comment into an answer since it seemed to have solved your issue...

This client code:

const socket = io.connect('http://localhost:1923');

won't work anywhere except on the same computer as the server is on. localhost is, by definition`, the local computer and only the local computer. You will need to connect by IP address or by DNS name.

Perhaps you want this:

const socket = io.connect('');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download