I want to Connect My Node JS App With Qt(C++) program, I'm using Socket.io for node JS (The Server) and QWebSocket for the Qt Program (the client).
But after all my trials i don't get to work. it shows me the error from the client side:
QAbstractSocket::RemoteHostClosedError
and from the server side, no signs of incoming connections.
here is my source code for that purpose:
Node JS Server:
var io = require('socket.io')(8082);
io.on('connection', function (socket) {
io.emit('this', 'Hey Welcome!');
console.log("New connection!");
socket.on('private message', function (from, msg) {
console.log('I received a private message by ', from, ' saying ', msg);
});
socket.on('disconnect', function () {
io.emit('user disconnected');
});
});
Qt C++ client:
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
{
ui->setupUi(this);
webSocket = new QWebSocket();
webSocket->open(QUrl(("ws://localhost:8082")));
connect(webSocket, SIGNAL(connected()), this, SLOT(isConnected()));
connect(webSocket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslError(QList<QSslError>)));
connect(webSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(logError(QAbstractSocket::SocketError)));
connect(webSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(newMessage(QString)));
connect(webSocket, SIGNAL(textFrameReceived(QString,bool)), this, SLOT(newMessageBit(QString,bool)));
}
Widget::~Widget()
{
delete ui;
}
void Widget::isConnected()
{
webSocket->sendTextMessage("Hello From Qt!!!");
}
void Widget::logError(QAbstractSocket::SocketError err)
{
qDebug() << "Error: ";
qDebug() << err;
}
void Widget::sslError(QList<QSslError> errors)
{
qDebug() << "SSLError: ";
qDebug() << errors;
webSocket->ignoreSslErrors(errors);
}
void Widget::newMessage(QString msg)
{
qDebug() << msg;
}
void Widget::newMessageBit(QString msg, bool isLast)
{
qDebug() << msg;
qDebug() << isLast;
}
I'm also getting these errors(at runtime) from the debug console
QSslSocket: cannot resolve TLSv1_1_client_method
QSslSocket: cannot resolve TLSv1_2_client_method
QSslSocket: cannot resolve TLSv1_1_server_method
QSslSocket: cannot resolve TLSv1_2_server_method
QSslSocket: cannot resolve SSL_select_next_proto
QSslSocket: cannot resolve SSL_CTX_set_next_proto_select_cb
QSslSocket: cannot resolve SSL_get0_next_proto_negotiated