Socket.io (Node.js) Doesn't Detect Connected QTcpSocket

549 views Asked by At

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.

1

There are 1 answers

2
mscdex On

socket.io is not for regular TCP sockets. What you want instead is the built-in net module, specifically net.createServer() which returns a net.Server instance that you can use to listen for plain TCP connections.