I'm trying to connect a QTcpSocket to a Nodejs application. The C++ QT Code is:
nodeSocket = new QTcpSocket(this);
nodeSocket->connectToHost("127.0.0.1", 3000);
if (nodeSocket->waitForConnected(3000))
{
qDebug() << "Connected!";
}
The Node.js code is:
var server = express().listen(3000);
var io = require('socket.io').listen(server);
io.sockets.on('connection', function (socket) {
console.log('A new client connected! ID: ' + socket.id);
});
I know the QT socket is able to connect and it goes through the condition for connecting, but it's not getting through io.sockets.on in the Javascript function to indicate that a new client is connected.
socket.io
is not for regular TCP sockets. What you want instead is the built-innet
module, specificallynet.createServer()
which returns anet.Server
instance that you can use to listen for plain TCP connections.