{NodeJS}得到了愚蠢的错误getaddrinfo ENOTFOUND echo.websocket.org

时间:2015-11-15 12:34:26

标签: node.js websocket

我使用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,但它没有帮助。我该如何解决?

1 个答案:

答案 0 :(得分:0)

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