Forward all data over a QTcpSocket

721 views Asked by At

I have a ssh tunnel setup using libssh. However, this does not bind it to a local port, so what I need essentially is to forward all data received on a port to the ssh channel. However, when I do this:

QTcpSocket* socket = new QTcpSocket();
socket->bind(27017);

QObject::connect(socket, &QTcpSocket::readyRead, this, &Forwarder::newData);

The newData slot is never invoked i.e. the readyRead on QTcpSocket is never invoked. Whenever I try to connect to the port via an external script, I get an Operation timed out. I am sure that atleast the port is opened because when the Qt application is not running, the error I get is Connection refused.

I have considered using QTcpServer, however, how do I even handle this case? I will probably get newConnection signals, but what data do I write to the ssh channel? How would I handle multiple incoming connections for a QTcpServer? Isn't a connection request also a data packet? Can I just not forward everything to the channel (The ssh channel I am referring to is akin to a fd that I can simple write to).

0

There are 0 answers