1

请帮忙解决问题:

当我启动 nats 服务器监听 4222 port: ./gnatsd --addr localhost --port 4222,然后 ./ws-tcp-relay localhost:4222 -p 4223尝试使用 websocket-nats 通过 websockets 连接(例如在 service.js 中):

'use strict';
const nats = require('websocket-nats').connect('ws://localhost:4223');

我收到此错误:

node server.js 
events.js:188
      throw err;
      ^

Error: Unhandled "error" event. (Could not connect to server: Error: getaddrinfo ENOTFOUND localhost:4223 localhost:4223:4223)
    at Client.emit (events.js:186:19)
    at Socket.<anonymous> (/home/dev/projects/node-pub/node_modules/websocket-nats/lib/nats.js:404:14)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

但是,如果我尝试使用 tcp 客户端端口 4222 直接连接到 nats,则连接建立成功:

const nats = require('nats').connect('nats://localhost:4222');
4

0 回答 0