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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:01:01+00:00 2026-06-11T18:01:01+00:00

Using Node.js and socket.io, the following works fine unti trying to broadcast back to

  • 0

Using Node.js and socket.io, the following works fine unti trying to broadcast back to the clients.

I am getting broadcast undefined?

var http = require('http'),
    sys  = require('sys'),
    fs   = require('fs'),
    io   = require('socket.io');

var server = http.createServer(function(request, response) {
  response.writeHead(200, {
    'Content-Type': 'text/html'
  });

  var rs = fs.createReadStream(__dirname + '/index.html');
  sys.pump(rs, response);

});

var socket = io.listen(server);
debugger;
socket.on('connection', function(client) {
  debugger;
  var username;

  client.send('Welcome to this socket.io chat server!');
  client.send('Please input your username: ');

  client.on('message', function(message) {
    if (!username) {
      username = message;
      client.emit('Welcome, ' + username + '!');
      return;
    }
    socket.broadcast.send('a message');
    //io.socket.send('a message');
    //io.socket.emit('message', username + ' sent: ' + message);
  });

});

server.listen(4000);
  • 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-11T18:01:02+00:00Added an answer on June 11, 2026 at 6:01 pm

    If you want to send message from specific client to rest of the clients then use:

    client.broadcast.send('a message');
    

    To send message to all clients use:

    socket.sockets.send('a message');
    

    sys, pump, they are all deprecated.

    https://github.com/joyent/node/wiki/API-changes-between-v0.6-and-v0.8
    http://nodejs.org/api/util.html#util_util_pump_readablestream_writablestream_callback

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

Sidebar

Related Questions

I'm trying to install Node, socket.io and npm using the following: cd ~ sudo
I'm using Socket.IO on Node.js. The Example here: http://socket.io/#how-to-use First Example. I have tested
I'm using Node.js 0.6.9, and am trying to send a datagram broadcast package. Code:
I'm using node.js and socket.io. I'm using http-proxy to use port 80 on a
When using https.request with node.js v04.7, I get the following error: Error: socket hang
I trying to make a small chat website using node.js and socket.io. To include
I'm trying to set up a simple chat using node.js (no express) and socket.io.
I am using socket.io to connect to my node server using the following script:
I'm using node.js and socket.io to display countdown timers. The timers are being run
I'm interested in using Node.js as a socket server for stream-based communication with tens

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.