net.createConnection 似乎总是给 ECONNREFUSED。我做了一个 tcpdump 并且不太清楚我在找什么。
代码:
const net = require('net');
const client = net.createConnection({ port: 8124}, () => {
// 'connect' listener.
console.log('connected to server!');
client.write('world!\r\n');
});
client.on('error', function(e) {
console.log(e);
console.log(e.message);
});
client.on('data', (data) => {
console.log(data.toString());
client.end();
});
client.on('end', () => {
console.log('disconnected from server');
});
输出:
Error: connect ECONNREFUSED 127.0.0.1:8124
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 8124
}
connect ECONNREFUSED 127.0.0.1:8124
链接pcap文件查看包点我