问题描述:

I use ws library.

The code:

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");

};

The console returns:

{ [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 } }

Yesterday it worked, but today, it doesn't work. I tried reinstalling Node.JS and ws, but it didn't help. How can I fix it?

网友答案:

I ran cmd.exe and ping echo.websocket.org. Then I tried run my script again. I don't know why, but it worked. Probably it's a bug with Node.JS DNS.

相关阅读:
Top