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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:44:43+00:00 2026-05-26T11:44:43+00:00

I am quite new to nodeJS and Socket.IO and am facing a problem. Is

  • 0

I am quite new to nodeJS and Socket.IO and am facing a problem.

Is there any way to know the type of event inside a Socket.IO handler? I have this kind of code:

// Fire the appropriate callback when we receive a message
// that.received is an array of callback functions
for (var event in that.received) {
    socket.on(event, function(message) {
        // Of course, this won't work because of "event" scope
        that.received[event](message, this);
    });
}

So, what I want to know is the actual value of “event” that triggered my handler.
I tried to inspect available variables with Chrome developer tools, but I wasn’t able to find anything.

I need to do this because I am writing some kind of wrapper class around Socket.IO to handle multiple sockets (a long storty about fallback servers). I want it to be generic enough to pass my handlers to it.

Any ideas?

  • 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-26T11:44:44+00:00Added an answer on May 26, 2026 at 11:44 am

    OK, stupid question.

    I just need to do this:

    // Fire the appropriate callback when we receive a message
    for (var event in that.received) {
        socket.on(event, that.received[event]);
    }
    

    I was passing “this” to my callback function, which is just stupid. My callbacks looked like this:

    function myCallback(message, socket) {
        // Some code...
        socket.emit('ack', message.id);
        // Some code...
    }
    

    But all I have to do is this:

    function myCallback(message) {
        // Some code...
        this.emit('ack', message.id);
        // Some code...
    }
    

    So I don’t have the scope problem anymore.

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

Sidebar

Related Questions

Im quite new to Java and i have stumbled upon the following problem. Im
I'm quite new to programming, and I was wondering if there is a good
Hi I am quite new to php but i have been following some tutorials
I'm quite new to php and have been reading Larry Ullman book to develop
I'm quite new to OpenId and I'm having a bit of a problem understanding
I'm quite new to Node.js, so please bear with me... Bascially, I have a
Quite new to this mocking thing, I have a couple of questions. Correct me
Basically i am quite new to PHP and recently i have had heard quite
I am quite new to ICEfaces but already have experience with JSF/Facelets and the
I got two problem I'm quite new to node.js i worked through some tutorials

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.