Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't bind to localhost:80 (webserver or any other service listening on this port). #1252

Closed
christophorus opened this issue Jan 2, 2023 · 1 comment
Labels

Comments

@christophorus
Copy link

christophorus commented Jan 2, 2023

const { Client } = require('ssh2');

const conn = new Client();
conn.on('ready', () => {
    console.log('Client :: ready');
    conn.forwardIn('127.0.0.1', 80, (err) => {
        if (err) throw err;
        console.log('Listening for connections on server on port 8000!');
    });
}).on('tcp connection', (info, accept, reject) => {
    console.log('TCP :: INCOMING CONNECTION:');
    console.dir(info);
    accept().on('close', () => {
        console.log('TCP :: CLOSED');
    }).on('data', (data) => {
        console.log('TCP :: DATA: ' + data);
    }).end([
        'HTTP/1.1 404 Not Found',
        'Date: Thu, 15 Nov 2012 02:07:58 GMT',
        'Server: ForwardedConnection',
        'Content-Length: 0',
        'Connection: close',
        '',
        ''
    ].join('\r\n'));
}).connect(connectConfig);

When service is listening on the port for example 8080 all is fine( conn.forwardIn('127.0.0.1', 8080, (err) => {}

Below fix the problem, but all makes work around. I will appreciate any hint.

net.createServer(function (from) {
        var to = net.createConnection({
            host: host,
            port: 80
        });
        from.pipe(to);
        to.pipe(from);
    }).listen(8080, 80);
@mscdex
Copy link
Owner

mscdex commented Jan 2, 2023

ssh2 doesn't bind any local ports or automatically forward connections for you (e.g. like with OpenSSH's -L and -R forwarding), that is up to you to do. The reason for this is that it gives you the opportunity to handle connections in-process.

@mscdex mscdex added the question label Jan 2, 2023
@mscdex mscdex closed this as not planned Won't fix, can't repro, duplicate, stale Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants