node.js - Node Net refuses connection no matter what on learnyounode -
i continuously following error:
✗ error connecting localhost:20496: connect econnrefused
note: local host number changing.
on cloud9.ide error happens before timeout, , on my computer error happens after timeout. (it happens in both areas think it's local host problem)
the code i'm using follows:
var net = require('net'); function zero(i) { return (i < 10 ? '0' : '') + i; } function () { 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 net
module doesn't work , http
module did. feel has port being listened to, changed 3306 , there no differences in output.
i believe i'm running latest version of node , learnyounode, , os widnows7.
versions:
- npm:2.11.2
- node:0.12.5
could try (taken docs) , post 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 test this:
telnet localhost 8124
to listen on socket /tmp/echo.sock third line last changed to
server.listen('/tmp/echo.sock', function() { //'listening' listener
use nc connect unix domain socket server:
nc -u /tmp/echo.sock
Comments
Post a Comment