在nodejs应用上使用netcat测试zeroMQ tcp套接字

时间:2018-11-28 23:25:24

标签: node.js tcp zeromq netcat

我有一个带有简单的zeroMQ响应器的nod​​e.js应用程序,该应用程序侦听端口5555并将其收到的消息回传给发送方。

我正在尝试测试侦听器是否正在接收消息,但是 1)建立连接后,netcat无法正确发送以下标准输入
要么 2)听众没有收到消息吗?

终端输出:(stdin在怪异的字符之后开始-也不确定为什么netcat在连接后输出它)

$ nc -vv localhost 5555
nc: connectx to localhost port 5555 (tcp) failed: Connection refused
found 0 associations
found 1 connections:
     1: flags=82<CONNECTED,PREFERRED>
    outif lo0
    src 127.0.0.1 port 53852
    dst 127.0.0.1 port 5555
    rank info not available
    TCP aux info available

Connection to localhost port 5555 [tcp/personal-agent] succeeded!
�"hello"
"asdjkflasd"

app.js:

const zmq = require('zeromq');

// ==================== zeromq response ====================
// socket to talk to clients
var responder = zmq.socket('rep');

responder.on('message', function(request) {
  console.log(request);
  console.log("Received request: [", request.toString(), "]");

  // do some 'work'
  setTimeout(function() {
    // send reply back to client.
    responder.send(request.toString());
  }, 1000);
});

responder.bind('tcp://127.0.0.1:5555', function(err) {
  if (err) {
    console.log(err);
  } else {
    console.log("Listening on 5555…");
  }
});
process.on('SIGINT', function() {
  responder.close();
});

0 个答案:

没有答案