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)