首页新闻找找看学习计划

nodejs创建TCP客户端不能连接服务器,来兄弟帮下忙

0
[已关闭问题] 关闭于 2016-03-28 11:29

var net = require('net');

const HOST = '127.0.0.1';
const PORT = 18001;
var tcpClient = new net.Socket();

tcpClient.connect(PORT,HOST,function(){
    console.log('connect success');
    tcpClient.write('this is tcp client by Node.js');
});

tcpClient.on('data',function(data){
    console.log('received: ',data.toString());
});

 

[root@localhost test]# node tcpClient.js

错误如下:

 events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: connect ECONNREFUSED
    at errnoException (net.js:905:11)
    at Object.afterConnect [as oncomplete] (net.js:896:19)

海源的主页 海源 | 菜鸟二级 | 园豆:226
提问于:2016-03-27 22:54
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册