简体   繁体   中英

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

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-in net module, specifically net.createServer() which returns a net.Server instance that you can use to listen for plain TCP connections.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM