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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:21:03+00:00 2026-06-11T20:21:03+00:00

I am using Socket.IO to have a client webpage fetch data dynamically from my

  • 0

I am using Socket.IO to have a client webpage fetch data dynamically from my Node.JS server. On the server-side, I am forwarding the request to a Python backend using the zeromq socket library (REQ/REP structure, see the rrclient.js example from zguide).

However, since my server is acting as the socket.io server, I have to wrap my response as follows in order to send it back to the specific client:

socket.on('app_request',function(appRequest){
      //route this request to the backend.
      var results = fetch_data(appRequest);
      //return it to the client
      socket.emit('app_results',results);
  });

so the fetch_data function uses a zmq socket (socket.send) to push a request to the server.

But the Node ZMQ socket responds to request using a socket.on(‘message’,function(){}); listener and doesn’t actually return anything.

How can I use socket.on(‘message’,function(){}); to return a value to the specific function that initiated a socket.send() request?

In other words, how can I get a client’s socket.io request to have Node.JS fetch relevant data from a python backend using ZMQ, then return it back to the socket.io client? (in a non-blocking fashion of course)

  • 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-11T20:21:04+00:00Added an answer on June 11, 2026 at 8:21 pm

    I’ve done something similar, you’ll want to rework it like so;

    socket.on('app_request',function(appRequest){
      //route this request to the backend.
      fetch_data(appRequest, function(err, results) {
           socket.emit('app_results',results);
      });
    });
    

    zmq is non-blocking so the response is not received before your sending it down to socket.io, using this method you can adjust your fetch_data method to store the callback until the response is returned and then fire it.

    Rough fetch_data for inspiration only not tested;

    var zmq = require('zmq'),
        req = zmq.socket('req'),
        count = 0,
        jobs = {};
    
    
    req.on('message', function(response) {
        var args  = JSON.parse(response),
            reply = args[0],
            id    = args[i];
    
        if (id && jobs[id]) {
             jobs[id].apply(null, Array.isArray(reply) ? reply : [reply]);
    
             delete jobs[id];
        }
    }
    
    function fetch_data(appRequest, callback) {
        var data = JSON.stringify([appRequest, count]);
    
        jobs[count] = callback;
    
        req.send(data);
    
        ++count;
    }
    

    Then on the other side parse the json and keep the id and send it back with the response.

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

Sidebar

Related Questions

I have strange problem with receiving data from socket. On client im using air
I have a client server situation in which I receive data using read(socket, char_buf,
I have Android client app that communicates with server using Socket . On my
I have created my web socket server and client using this simple tutorial here
I have developed a Java server using Eclipse that accepts TCP socket connection from
I have browser client Javascript which opens a WebSocket (using socket.io) to request a
Here's my problem: I have server A, running node.js and using socket.io for communicating
I have implemented the client server using socket programming in C on Unix OS.
I have a server application and a client application. I'm using socket to communicate
I have got a Client/Server Application that using Asynchronous Socket.My problem is i cant

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.