Node Network refuses to connect no matter what is in class

I keep getting the following error:

✗ Error connecting to localhost: 20496: connecting ECONNREFUSED

Note: the local host number always changes.

In cloud9.ide, the error happens before the timeout, and on my computer, the error occurs after the timeout. (this happens in both areas, so I think it is a local node issue)

The code I'm using looks like this:

var net = require('net');
function zero(i) {
  return (i < 10 ? '0' : '') + i;
}
function now () {
  var d = new Date();
  return d.getFullYear() + '-' + zero(d.getMonth()) + '-'
    + zero(d.getDate()) + ' ' + zero(d.getHours()) + ':'
    + zero(d.getMinutes());
}

var server = net.createServer(function (socket) {
    socket.error(function(){
        console.log("Error");
    });
  socket.end("FOUND:"+now() + '\n');
}).listen(8000);

      

I don't understand why the module is net

not working and the module http

did. I feel like it has something to do with the port that is listening, but I changed it to 3306 and there was no difference in output.

I believe I am running the latest node and learnyounode and my OS is widnows7.

versions:

  • Npm: 2.11.2
  • Node: 0.12.5
+3


source to share


1 answer


Could you please try (taken from the docs) and post the results:

var net = require('net');
var server = net.createServer(function(c) { //'connection' listener
  console.log('client connected');
  c.on('end', function() {
    console.log('client disconnected');
  });
  c.write('hello\r\n');
  c.pipe(c);
});
server.listen(8124, function() { //'listening' listener
  console.log('server bound');
});

      

And you will eventually experience it like this:



telnet localhost 8124

      

To listen to the socket /tmp/echo.sock, the third line from the last one will simply be changed to

server.listen('/tmp/echo.sock', function() { //'listening' listener

Use nc to connect to a UNIX domain socket server:

nc -U /tmp/echo.sock

+2


source







All Articles