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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:04:48+00:00 2026-06-17T20:04:48+00:00

I am using nodejs and socketio. I made a private chat app which sends

  • 0

I am using nodejs and socketio. I made a private chat app which sends message to selected user.

My current code is :

          chat_room.sockets.socket(user).emit(
                'chat', 
                { 
                    message : message,
                    from : sockets[socket.id].username
                }
            );

Now I created rooms and I want to send message to a user of a specific room.

I tried below code but not working

socket.get('room', function(err, room) {
         chat_room.sockets.socket(room)(user).emit(
                'chat', 
                { 
                    message : message,
                    from : sockets[socket.id].username
                }
            );

});

Its wrong and it gave me an error :

C:\Users\Niraj\Desktop\node\joomla-chat\app.js:62
chat_room.sockets.socket(room)(user).emit(
^ TypeError: object is not a function
at chat_room.sockets.on.socket.on.socketID (C:\Users\Niraj\Desktop\node\joomla-chat\app.js:62:45)
at Client.get (C:\Users\Niraj\Desktop\node\joomla-chat\node_modules\socket.io\lib\stores\memory.js:86:3)
at Socket.get (C:\Users\Niraj\Desktop\node\joomla-chat\node_modules\socket.io\lib\socket.js:258:14)
at Socket.chat_room.sockets.on.socket.on.socketID (C:\Users\Niraj\Desktop\node\joomla-chat\app.js:48:16)
at Socket.EventEmitter.emit [as $emit] (events.js:96:17)
at SocketNamespace.handlePacket (C:\Users\Niraj\Desktop\node\joomla-chat\node_modules\socket.io\lib\namespace.js:335:22)
at Manager.onClientMessage (C:\Users\Niraj\Desktop\node\joomla-chat\node_modules\socket.io\lib\manager.js:487:38)
at WebSocket.Transport.onMessage (C:\Users\Niraj\Desktop\node\joomla-chat\node_modules\socket.io\lib\transport.js:387:20)
at Parser. (C:\Users\Niraj\Desktop\node\joomla-chat\node_modules\socket.io\lib\transports\websocket\hybi-16.js:39:10)
at Parser.EventEmitter.emit (events.js:96:17)

How can I send message to a specific user of a room

——————————-EDIT—————————-
So if I do :

socket.get('room', function(err, room) {
              chat_room.sockets.socket(user).emit(
                    'chat', 
                    { 
                        message : message,
                        from : sockets[socket.id].username
                    }
                );

        });

Then this will fire the message to Mr.X to ABC room

Am I right?

  • 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-17T20:04:49+00:00Added an answer on June 17, 2026 at 8:04 pm

    Regardless of whether or not the user you want to contact is in a room, the easiest way to contact them, provided you have the proper identifying information, is still just a simple socket.emit().

    You stated that you already have their socket.id; if so, then getting their socket object is as simple as: io.sockets.sockets[socket.id].

    To send a message you can then say: io.sockets.sockets[socket.id].emit('identifier', data);

    That should answer your question, although these are two additional things you may find helpful:

    -To broadcast to the entire room you are focusing on: io.sockets.in('room').emit('event_name', data)

    -There is a very rich amount of information regarding both rooms and connected sockets stored within io.sockets. I strongly recommend that you put a console.log(io.sockets); in the beginning of your code and inspect the object closely to see what else you can access.

    Hope this helps!

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

Sidebar

Related Questions

I've made a chat client with different chat rooms in NodeJS, socketIO and Express.
I'm using nodejs 0.4.7 to make the request, this is my code: var post_data
I'm using: nodejs (0.6.8) expressjs (2.5.2) socket.io (0.8.7) node-db-mysql (0.7.6) Currently the code works
I am developing a simple application using the current latest versions of nodejs +
I want to build a chat system in nodeJs + MYSQL using php. It
I am developing a kind of multi purpose server using nodeJs (net,express,socketIo). Multipurpose means
I have an nodejs chat app where multiple clients connect to a common chat
Using socketio on the client side and nodejs with socketio on the server side,
I was thinking of building a web app which would be single page, using
I'm using Nodejs and Socket.io. When the client connects, new JavaScript objects are created.

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.