启动节点快速应用程序时ECONNREFUSED

时间:2016-02-20 19:06:38

标签: javascript node.js express

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED 127.0.0.1:4562
    at Object.exports._errnoException (util.js:837:11)
    at exports._exceptionWithHostPort (util.js:860:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1060:14)

这是我的代码

var express = require('express');
var net = require('net');
var app = express();
var i = 0;
app.get('/', function (req, res) 
{
    i = i+1; //no of clinets request gin ne ki liye
    console.log(i + "fa..sa");
    var client = net.connect({port: 4562},"192.168.202.101", function() {  
        console.log('connected to server!'); });
    client.write("Ho gaya bhai");
    client.end();
    res.send('ho gaya bhai..');
});

app.listen(6544);

1 个答案:

答案 0 :(得分:0)

从错误消息中可以看出,您拨打net.connect的方式有误。看起来您想要连接到192.168.202.101:4562,但是您尝试连接到'127.0.0.1:4562'。尝试:

net.connect({ port: 4562, host: "192.168.202.101"}, function(){});

或:

net.connect(4562, "192.168.202.101", function() {});