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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:15:17+00:00 2026-06-06T01:15:17+00:00

I have a socket.io server listening for certain events on sockets. Whenever an event

  • 0

I have a socket.io server listening for certain events on sockets. Whenever an event is fired, it passes the event data to an event-handler. My question is, should the event handler have a reference to the server, and respond directly to the events like so?

eventHandler.handle = function(event){
myServerReference.emit(event, etc);
}

Or should the event handler fire an event when it has data to send, and the server should listen for it and handle the data sending like so:

eventHandler.onResponse(function(data){ server.emit(data); }

Which is a better approach in the long run? Is there a better way to design this?

  • 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-06T01:15:19+00:00Added an answer on June 6, 2026 at 1:15 am

    While the short answer is “it depends,” a good OO practice is to keep in mind the “S” of “SOLID”:

    In object-oriented programming, the single responsibility principle states that every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility.

    If the unit of code in which the event handler lives is doing too much (that is, doing someone else’s job), you should move that functionality elsewhere.

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

Sidebar

Related Questions

I have a Java socket server program listening on a specific port. When receiving
I have c++ socket server and android client. Server constantly sends data to the
I have a socket server in php server.php $master = WebSocket(localhost,800); $sockets = array($master);
I have a java server listening on a Socket. I can send and receive
I have Nginx as my front-end web server listening on port 80. And certain
I have a 'C# server' program listening to '127.0.0.1', port 5500, using .NET socket,
I have a socket server listening on 2 ports, 1 port for the socket
Hi I have a running socket server written with PHP. The server is listening
Let's say I have a server socket listening on port no 5010. When client
I have a java program which has a server-socket listening infinitely. In case of

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.