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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:40:18+00:00 2026-06-07T09:40:18+00:00

From what I can understand, once I create a socket, I can then create

  • 0

From what I can understand, once I create a socket, I can then create an array to store it with

userArray[socket.nickname]=socket;

I can then send a message to it with:

  io.sockets.socket(userArray[data.to]).emit('private message', tstamp(), socket.nickname, message);

The basic logic is to store a copy of each socket in an object, identified by nickname. When I want to send a message to that socket, I use the copy of the socket, and send the message via io.sockets.socket(id).emit(). The entire server code is below:

io.sockets.on('connection', function (socket) {
  socket.on('user message', function (msg) {
    socket.broadcast.emit('user message', tstamp(), socket.nickname, msg);
    updateLog('user message', socket.nickname, msg);
  });

   socket.on('private message', function(data) {
        socket.get(data.nickname, function (err, name) {    
        console.log('Chat message by ', name);
        });
        updateLog('private message', socket.nickname, data.message);
        message=data.message;
        io.sockets.socket(userArray[data.to]).emit('private message', tstamp(), socket.nickname, message);
   });

  socket.on('get log', function () {
    updateLog(); // Ensure old entries are cleared out before sending it.
    io.sockets.emit('chat log', log);
  });

  socket.on('nickname', function (nick, fn) {
    var i = 1;
    var orignick = nick;
    while (nicknames[nick]) {
      nick = orignick+i;
      i++;
    }
    fn(nick);

    nicknames[nick] = socket.nickname = nick;
    userArray[socket.nickname]=socket;

    socket.set('nickname', nick, function () { socket.emit('ready'); });

    socket.broadcast.emit('announcement', nick + ' connected');
//    io.sockets.socket(userArray[nick]).emit('newID', 'Your name is: ' + nick, '. Your ID is: '+ userArray[nick]);
    io.sockets.emit('nicknames', nicknames);
  });   
  • 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-07T09:40:20+00:00Added an answer on June 7, 2026 at 9:40 am

    It’s unclear what your actual question is, but if you’ve stored a socket object as the value of an object key (which is what you’re doing; userArray is quite a misleading name since it’s not an array), then you just call methods on the value. IOW, instead of

    io.sockets.socket(userArray[data.to]).emit(...
    

    you’d just write:

    userArray[data.to].emit(...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As you can understand from title, i modified Settings.cs file.Added some properties, some code
I understand that we can set the various style attributes from code behind using
Can someone please explain how to understand a logcat from an android force close.
As I understand it I can use reverse P/Invoke to call C# from C++.
From my reading of some android forensic articles i understand that sqlite records can
Using a delegate I can call any function asynchronously. From the documentation I understand
From where can I get complete set of Indentation rules for Haskell code writing?
Launch app from homescreen can't get remote push payload? But launch from Notification Center
instead of popup from center can we change to another animation (eg, undo animation)?
Why can't I access 'B' in the following from 'A' but can from the

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.