{NodeJS}出现愚蠢的ws错误getaddrinfo ENOTFOUND echo.websocket.org



我使用ws库。

代码:

WebSocket = require("ws");
ws = new WebSocket("ws://echo.websocket.org");
ws.onopen = function() {
    ws.send("Hello, world!");
};
ws.onmessage = function(msg) {
    console.log("Message: " + msg.data);
};
ws.onerror = function(e) {
    console.log(e);
};
ws.onclose = function() {
    console.log("Closed");
};

控制台返回:

{ [Error: getaddrinfo ENOTFOUND echo.websocket.org echo.websocket.org:80]
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'echo.websocket.org',
  host: 'echo.websocket.org',
  port: 80,
  type: 'error',
  target:
   WebSocket {
     domain: null,
     _events:
      { open: [Object],
        message: [Object],
        error: [Object],
        close: [Object] },
     _eventsCount: 4,
     _maxListeners: undefined,
     _socket: null,
     _ultron: null,
     _closeReceived: false,
     bytesReceived: 0,
     readyState: 0,
     supports: { binary: true },
     extensions: {},
     _isServer: false,
     url: 'ws://echo.websocket.org',
     protocolVersion: 13 } }

昨天起作用了,但今天不起作用。我试着重新安装Node.JSws,但没有帮助。我该怎么修?

我运行了cmd.exeping echo.websocket.org。然后我再次尝试运行我的脚本。我不知道为什么,但它起了作用。可能是Node.JS DNS的一个错误。

相关内容

  • 没有找到相关文章

最新更新