Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7827051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:41:57+00:00 2026-06-02T09:41:57+00:00

I finally got Socket.IO to work properly, but I have encountered a strange problem.

  • 0

I finally got Socket.IO to work properly, but I have encountered a strange problem.

I am not sure if this is the best way, but I am using:

io.sockets.clients().length

This returns the number of clients connected to my server. The problem is after a few connects and disconnects of users, the number starts to stay higher than it should be.

For instance, if I connect and ask my friends to, the number goes up which is correct. But when we start to disconnect and reconnect the number does not decrease.

I am running the Node.js and Socket.IO server on a VMware Ubuntu server.

Why is this or is there a better method for finding out how many people are connected to the server?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:41:58+00:00Added an answer on June 2, 2026 at 9:41 am

    There is a github issue for this. The problem is that whenever someone disconnects socket.io doesn’t delete ( splice ) from the array, but simply sets the value to “null”, so in fact you have a lot of null values in your array, which make your clients().length bigger than the connections you have in reality.

    You have to manage a different way for counting your clients, e.g. something like

    socket.on('connect', function() { connectCounter++; });
    socket.on('disconnect', function() { connectCounter--; });
    

    It’s a mind buzz, why the people behind socket.io have left the things like that, but it is better explain in the github issue, which I posted as a link!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've finally got this PHP email script working (didn't work on localhost…), but my
I finally got Bootstrap tabs to work. I was wondering if there's a way
I've have finally got the datepicker to work on my MVC demo site. One
I have been working on this Tab View and I finally got it working
I (finally) got ACL to work properly, based on group permissions. However when I
I finally got AdMob to work on an android game I made, but it
I finally got this to work using the javascriptserializer to deserialize the json content.
I finally got some understanding of how Ninject handles DI, but have faced the
Well I added and finally got Sharekit to work with facebook using FBConnect, but
I have finally got the green light to use Memcached in our project (after

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.