TCP Server with Glitch

Can I create a TCP server with Glitch?

I tried a couple of variations using the net node module to create a TCP server.

What I learned is:

  • The few ports that are open are being used (see below)
  • Other ports can be used but are not accessible for testing (see port list)
  • For some reason connections are being drop or reset (ECONNREFUSED and ECONNRESET) as soon as they connect (see example below).
  • Neither netcat, nc or socat are installed in the assigned instance making difficult to test TCP connections
  • Unable to install LWP::Simple perl module since it requires super user permissions as an alternative to netcat or similar tools.

Port list
Ports that are listening are in the range of 1081-1087 for tcp and tcp6 so these are not usable.
Other ports like 8080, and range 3000-5000 drop connections.

Example
I’ve tried variations of the following example without success:

var net = require('net');

var client = new net.Socket();
client.connect(process.env.PORT, 'localhost', function() {
  console.log('Connected');
  client.write('Hello, server! Love, Client.');
});

client.on('data', function(data) {
  console.log('Received: ' + data);
  client.destroy();
});

client.on('close', function() {
  console.log('Connection closed');
});

client.on('error', function(e) {
  console.log('Connection error', e);
});

Output

Connection error { Error: connect ECONNREFUSED 127.0.0.1:3000
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3000 }
Connection closed

This is my progress, I’m sure someone with more expertise can put us in the right direction. Maybe I’m assuming wrong stuff but wanted to try and share.

The problem is that we route your requests through a proxy, and we need to use the HTTP Host headers to tell which project you’re trying to connect to. With a raw TCP connection, we don’t know where you’re trying to go. The closest you can get to this easily is to use a websocket.

1 Like