0

net.createConnection always seems to give ECONNREFUSED. I did a tcpdump and don't quite know what I'm looking for.

Code:

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');
});

Output:

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

Link to the pcap file to view the packets Click me

O. Jones
  • 103,626
  • 17
  • 118
  • 172
ZiiM
  • 31
  • 1
  • 6

2 Answers2

0

Use a tracer like tcpdump to see what is actually going on. The message, "connection refused," is actually a bit misleading. It doesn't actually mean that the host has identified you and is now refusing to talk to you.

Mike Robinson
  • 8,490
  • 5
  • 28
  • 41
  • I used wireshark to see what is happening and I don't quite know exactly what I am looking for. – ZiiM Mar 17 '21 at 15:50
0

Make sure you have a server running on port 8124 of your local machine (127.0.0.1). ECONNREFUSED means you dont.

O. Jones
  • 103,626
  • 17
  • 118
  • 172