0rpc/zerorpc-node

Node JS Client never gets response from Python server

lemieuxs opened this issue · 4 comments

Hi,

I am trying to make a little program using a python server and a nodejs client.

Here is my server:

# =====================================
# Function
# =====================================
class CMpyBikesWrapper():
    def get_all_networks(self):
        schemas = map(lambda name: re.sub(r'\.json$', '', name), pybikes.get_all_data())
        i = 0
        networks = []
        for schema in schemas:
            for cname, instance in pybikes.get_instances(schema):
                networks.append(instance)
        return networks

# =====================================
# Server
# =====================================
s = zerorpc.Server(CMpyBikesWrapper())
s.bind("tcp://0.0.0.0:9000")
print("Listening on port 9000")
s.run()

And this is my client:

    var zerorpc = require("zerorpc");
    var client = new zerorpc.Client();
    client.connect("tcp://127.0.0.1:9000");

    client.invoke("get_all_networks", function(error, res, more) {
        console.log(res);
        callback(res);
    });

    client.close()

My problem is that the answer never comes back from the server. I know that my request gets to the server and that there is no error.

Is there anything wrong in my node JS client. It also works when I try with a terminal as client

zerorpc --client --connect tcp://127.0.0.1:9000 get_all_networks

Hi, what is callback in your client?

My callback is a simple function for my API. But I think the problem is elsewhere because the console.log(res) does not log anything...

When i put a breakpoint on the console.log line it never stops.

function(err, result) {

        if (err)
        {
            req.stats.error = err;
            res.status(err.httpCode).json({error: err.error});
        }
        else
        {
            res.json(result);
        }

        next();
    });

I suppose printing the error doesn't work either? Does the helloworld on http://www.zerorpc.io/ works? I am all out of ideas.

I just did a clean project with only the Hello World from your site.

And I got this error in my node JS Client

/usr/local/bin/node --debug-brk=59893 --nolazy app.js
Debugger listening on port 59893
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: Uncaught, unspecified "error" event.
    at Error (native)
    at Client.emit (events.js:87:13)
    at MultiplexingSocket.<anonymous> (/Users/sebastienlemieux/node_modules/zerorpc/lib/util.js:33:17)
    at MultiplexingSocket.emit (events.js:107:17)
    at error (/Users/sebastienlemieux/node_modules/zerorpc/lib/socket.js:43:14)
    at null.<anonymous> (/Users/sebastienlemieux/node_modules/zerorpc/lib/socket.js:57:20)
    at emit (events.js:110:17)
    at Socket._flush (/Users/sebastienlemieux/node_modules/zerorpc/node_modules/zmq/lib/index.js:573:17)
    at exports.Socket._zmq.onReady (/Users/sebastienlemieux/node_modules/zerorpc/node_modules/zmq/lib/index.js:203:12)

Process finished with exit code 1