0

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.

wpakt
  • 1,073
  • 2
  • 13
  • 18

1 Answers1

3

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.

mscdex
  • 104,356
  • 15
  • 192
  • 153
  • I would rather not change the Node code. I tried using just QWebSocket (http://qt-project.org/doc/qt-5/qtwebsockets-echoclient-echoclient-cpp.html), but it wouldn't connect at all. – wpakt Nov 11 '14 at 23:44
  • `socket.io` is typically for browsers connecting to the server. You could use websockets, but then you have to have an implementation of the socket.io protocol to use in conjunction with the websocket. – mscdex Nov 11 '14 at 23:48