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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:53:11+00:00 2026-05-23T20:53:11+00:00

Messing around with socket.io just for proof of concept, everthing is working great so

  • 0

Messing around with socket.io just for proof of concept, everthing is working great so far except I can’t get my emit callback to work on the client side. I’ve got to be missing something stupid here, but documentation is not killer at the moment. The server picks up the “getSomeData” event just fine, no errors anywhere.

From what I could tell in the client socket.io source, it checks if the last argument to emit is a function and always uses it as a callback, but debugging any deeper than that was problematic for me.

I feel like I have to be missing some core concept here..Is this not what this.send(..) is supposed to do? I could find only 1 useage in the example apps, and none where the client side code for that event emission was available.

Update: just to be clear, I am in fact intentionally emitting the event client side. The purpose of this was to see if socket.io could be used to allow clients to pull data on request in addition to receiving pushes.

server:

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

io.sockets.on('connection', function (socket) {
    socket.on("getSomeData", function() {
        this.send({data: "some random data"});
    });
});

client: (console.log never happens)

<script type="text/javascript" src="http://localhost/socket.io/socket.io.js"></script>
<script type="text/javascript">
  var socket = io.connect('http://localhost');
  socket.emit("getSomeData", function(data) {
      console.log(data);
  });
</script>
  • 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-23T20:53:11+00:00Added an answer on May 23, 2026 at 8:53 pm

    It looks like you have some logic switched around, try…

    var io = require('socket.io').listen(80);
    
    io.sockets.on('connection', function (socket) {
        socket.emit("getSomeData",{data: "some random data"});
    });
    

    and client…

    <script src="http://localhost/socket.io/socket.io.js"></script>
    <script>
      var socket = io.connect('http://localhost');
      socket.on("getSomeData", function(data) {
          console.log(data);
      });
    </script>
    

    EDIT:

    var io = require('socket.io').listen(80);
    
    io.sockets.on('connection', function (socket) {
        socket.on("getSomeData", function(name,fn) {
            fn({data: "some random data"});
        });
    });
    

    Client

    <script src="http://localhost/socket.io/socket.io.js"></script>
    <script>
      var socket = io.connect('http://localhost');
      socket.emit("getSomeData", function(data) {
          console.log(data);
      });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started messing around with the lastfm API and I'm not sure why
Im just messing around with Ruby on Rails and HTML. This question isn't about
I just started learning about servers, and I am messing around with Google's App
When messing around with Haskell using GHC, I can use various meta-commands like :i
I'm just messing around with Visual Basic in Visual Studio 2010. Anyone know how
I was messing around with Core Animation trying to get it to work, and
I'm messing around with Node JS and socket.io and I'm a bit lost. In
Just messing around with Rails 3.1, which separates stylesheets via controllers. I'm assuming there
I am just messing around with Facebook connect on my local machine. I created
I am just messing around with reading input files with java until I got

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.