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 7440663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:53:09+00:00 2026-05-29T10:53:09+00:00

First of all, here’s my code: var users = {}; //User Connect io.sockets.on(‘connection’, function

  • 0

First of all, here’s my code:

var users = {};

//User Connect
io.sockets.on('connection', function (socket) {
    socket.emit('connected');
    socket.on('session', function (session){

     users[socket.id] = [session, socket];
     console.log(users);
     socket.emit("session_established");

     //User Disconnect
     socket.on('disconnect', function (){ 
         delete users[socket.id];
         socket.broadcast.emit('disconnect', { data : session});
    }); 


    //The above all works as it should, now here it what I want to do:

    socket.on('chatMessage', function (message, userID) {
    users[userIDsSocket][userID].emit('chatMessageResponse', { data: message});
    });


    });    
});

Here’s what my data looks like, (and this is for one user):

{ '17819180631362480757': //this value is users[socket.id]
[ '1',               //this value is session at the top, and in the bottom part userID 
 { id: '17819180631362480757', //The rest of this is the socket data
   namespace: [Object],
   manager: [Object],
   disconnected: false,
   ackPackets: 0,
   acks: {},
   flags: [Object],
   readable: true,
   store: [Object],
   _events: [Object] } ] }

so this is kind of what I need to do (Just in english terms of how it should function):

oh and first, there can be multiple userID’s/Session that are the same, if the user has the window open in more than one tab/computer/device, so it needs to send it to every socket that has the same userID

socket.on('chatMessage', function (message, userID) {  

for each (users[*].userID==userID)
{
    users[*][userID].emit('chatMessageResponse', { data: message});
}
});

So I don’t know how I would go through each part disregarding socket.id (where i placed [*]

  • 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-29T10:53:10+00:00Added an answer on May 29, 2026 at 10:53 am

    Change to:

    users[socket.id] = {userID:session, socketID:socket};
    

    then:

    for (var key in users)
    {
    if (users[key].userID==userID)
    {
    
    users[key].socketID.emit('new_request_response', { data: message});
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, here is my code snippet: var str = '<!--:de-->some german text<!--:--><!--:en-->some
First of all here are some code snippets: public void startThread() { this.animationThread =
first of all here is my code: @protocol SearchTableViewControllerDelegate @required - (void)didSelectFileCardsContent:(FileCardsContent*)content; @end @interface
Hi all first post here :) Let's start with a snippet of the code
First of all here is my code so that you can test it to
first of all this is my third question about web services here and i
I am new here so first of all my greetings to you I am
First of all, I do not believe this belongs on Superuser. This belongs here
Greetings to all! This is my first question here on stackoverflow. I have a
First of all: I am not an experienced ClearCase user, but I have lots

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.