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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:23:14+00:00 2026-05-26T04:23:14+00:00

I have two separate files that one is server-side JS. The other one is

  • 0

I have two separate files that one is server-side JS.

The other one is dynamically generated client-side PHP.

Those two files are successfully able to communicate each other through Socket.IO.

I understand that I can restrict namespace by using .of() but that cannot be used

to handle dynamically created chat rooms.

So I have decided to use both

.of('/chat') 

and the room feature

.join('room name') 

I could find server-side example and could not find client-side example with it.

Below is the only given server-side code snippet from Socket.IO github

var io = require('socket.io').listen(80);

io.sockets.on('connection', function (socket) {
    socket.join('justin bieber fans');
    socket.broadcast.to('justin bieber fans').emit('new fan');
    io.sockets.in('rammstein fans').emit('new non-fan');
});

1) I’m having trouble understanding below part.

socket.broadcast.to('justin bieber fans').emit('new fan');
io.sockets.in('rammstein fans').emit('new non-fan');

What is difference between those two?

2) why not using

socket.to('room name').emit('event')

instead of

io.sockets.in('room name').emit('new non-fan');

3) Lastly, I have found some documentation that using

.send()

instead of

.emit()

Somewhat .send() does not work for me and I want to know difference between those two.

Thanks and I apologize for multiple questions about Socket.IO.

  • 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-26T04:23:15+00:00Added an answer on May 26, 2026 at 4:23 am

    I have not used Socket.IO in quite some time, but

    1.) As the documentation states: “Broadcasting means sending a message to everyone else except for the socket that starts it.”
    After some searching with the Socket.IO code, you can take a look at Socket.prototye.packet, in /lib/socket.js.

    When you do your first call, you are setting the user to the “justin bieber fans” room, and broadcasting “new fan” for everyone but the socket.
    In the second instance, you are broadcasting for everyone in ‘rammstein fans’ to send ‘new non-fan’.

    2.)
    In the first call, you are emitting ‘event’ just for the single user, and the message to that single room.

    In the second call, you are sending for everyone in that room.

    3.)
    Once again, looking at the source code, they both look pretty similar, except that socket.io protocol accepts 3 different kind of messages: “event”, “json”, “message”.
    With .send, you can send a json string, or a message.
    With .emit, you are going to send an event to the client.
    It does not make much a difference, they are almost handled the same internally, but you should use the one that best fits your needs.

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

Sidebar

Related Questions

I have two separate installs of WebSphere. (Actually one is WebSphere Application Server V6.1
I have two factories ( post_factory.rb , comment_factory.rb ) in separate files. I'd like
I have two divs and two separate links that triggers slideDown and slideUp for
We have two databases, in two separate locations. One of the databases resides in
Purpose: Create a program that takes two separate files, opens and reads them, assigns
I have an array of images, and two nib files. One nib file has
I have a large amount of data to move using two PHP scripts: one
I have a multi-threaded server that handles client requests, and makes new threads for
Trying to separate out my LAMP application into two servers, one for php and
I have two rails apps that I am thinking about merging into one because

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.