1

我有一个在通过 sTunnel 配置的 EC2 实例上运行的小应用程序。

我的 sTunnel 是这样配置的

client = no
cert = /etc/stunnel/stunnel.pem
key = /etc/stunnel/stunnel.pem
[proxy]
connect = 127.0.0.1:3000
accept = private_ip:1500    

我在这里的理解是,我可以发送一个请求,private_ip:1500并将其移交给在本地主机上运行的进程,但是当我尝试向该 IP 地址发送一些内容时,我得到了一个ETIMEDOUT错误。

这是我提出请求的方式:

#!/usr/bin/env node

var net = require('net');

var HOST = 'private_ip';
var PORT = 1500;

var client = new net.Socket();
client.connect(PORT, HOST, function() {

    console.log('CONNECTED TO: ' + HOST + ':' + PORT);
});

// Add a 'data' event handler for the client socket
// data is what the server sent to this socket
client.on('data', function(data) {

console.log('DATA: ' + data);
    // Close the client socket completely
client.destroy();

});

// Add a 'close' event handler for the client socket
client.on('close', function() {
console.log('Connection closed');
});

任何人都可以帮忙吗?

编辑:

服务器监听如下:

var config = require('./config/config.js');
var net = require('net');
var timer = require('./timer.js');

const server = require('net').createServer({ pauseOnConnect: true });
const child = require('child_process').fork('anotherProcess.js', ['child']);

server.on('connection', function(socket) {
    child.send('socket', socket);
});

server.listen(config.proxy.port, function() {
    console.log((new Date()) + ' Server is listening on port ' + 
config.proxy.port);
});

server.on('error', function(err) {
    if (err.code === 'EADDRINUSE') {
        console.log('Address in use, retrying...');
        setTimeout(function() {
            server.close();
            server.listen(config.proxy.port);
        }, 1000);
    }
});
4

0 回答 0