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

  • SEARCH
  • Home
  • 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 7429217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:56:02+00:00 2026-05-29T08:56:02+00:00

I’m having a heck of a time finding documentation on io.sockets.clients() so I can

  • 0

I’m having a heck of a time finding documentation on io.sockets.clients() so I can retrieve the connected clients id, username, etc. When I alert(io.sockets.clients().length.toString()); it gives me the correct number, but I need to find the structure of the array. Is there a way I can figure out the array without knowing the structure? Much like php’s print_r()?

Code so far:

socket.on('switchRoom', function(newroom){
    var clients = io.sockets.clients();
    socket.emit('users', clients);
});

socket.on('users', function(usernames) {
    for(var client in usernames) {
        console.log(usernames[client].id + ' disconnected: ' +     usernames[client].disconnected)
    }
});

I receive this error after ‘switchRoom’ is fired

/home/ed/socket/chat/node_modules/socket.io/lib/parser.js:81
data = JSON.stringify(ev);
              ^
TypeError: Converting circular structure to JSON
at Object.stringify (native)
at Object.encodePacket (/home/ed/socket/chat/node_modules/socket.io/lib/parser.js:81:19)
at Socket.packet (/home/ed/socket/chat/node_modules/socket.io/lib/socket.js:202:21)
at Socket.emit (/home/ed/socket/chat/node_modules/socket.io/lib/socket.js:351:15)
at Socket.<anonymous> (/home/ed/socket/chat/app.js:58:10)
at Socket.$emit (events.js:64:17)
at SocketNamespace.handlePacket (/home/ed/socket/chat/node_modules/socket.io/lib/namespace.js:331:20)
at Manager.onClientMessage (/home/ed/socket/chat/node_modules/socket.io/lib/manager.js:436:38)
at WebSocket.onMessage (/home/ed/socket/chat/node_modules/socket.io/lib/transport.js:387:20)
at Parser.<anonymous> (/home/ed/socket/chat/node_modules/socket.io/lib/transports/websocket/hybi-07-12.js:38:10)
  • 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-05-29T08:56:03+00:00Added an answer on May 29, 2026 at 8:56 am

    Are you doing this on the client side (in the browser) or on the server side? You mention using alert, but I’m not aware of a clients() method on the client side that does what you want.

    On the server side, clients() returns an array of Sockets as defined by this method:

    /**
     * Retrieves all clients as Socket instances as an array.
     *
     * @api public
     */
    
    SocketNamespace.prototype.clients = function (room) {
      var room = this.name + (room !== undefined ?
         '/' + room : '');
    
      if (!this.manager.rooms[room]) {
        return [];
      }
    
      return this.manager.rooms[room].map(function (id) {
        return this.socket(id);
      }, this);
    };
    

    The Node.js console and browsers with dev tools provide a console object that allows debugging; generally, you can call console.log(something) where something pretty much anything; in the case of an object, the details of the object will be enumerated in one way or another.

    [Edit]

    Since you’re already using socket.set to store the username, perhaps you can try something like this:

    // server
    
    socket.on('connection', function(socket) {
      ...
      socket.on('disconnect', function() {
        socket.get('username', function (err, name) {
          socket.broadcast.emit('disconnected', name);
        });
      });
      ...
    });
    
    // client
    
    socket.on('connect', function () {
      ...
      socket.on('disconnected', function(name) {
        console.log(name + " disconnected.");
      });
      ...
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.