sslechoclient.cpp Example File
sslechoclient/sslechoclient.cpp
#include "sslechoclient.h"
#include <QtCore/QDebug>
#include <QtWebSockets/QWebSocket>
#include <QCoreApplication>
QT_USE_NAMESPACE
SslEchoClient::SslEchoClient(const QUrl &url, QObject *parent) :
QObject(parent)
{
connect(&m_webSocket, &QWebSocket::connected, this, &SslEchoClient::onConnected);
connect(&m_webSocket, QOverload<const QList<QSslError>&>::of(&QWebSocket::sslErrors),
this, &SslEchoClient::onSslErrors);
m_webSocket.open(QUrl(url));
}
void SslEchoClient::onConnected()
{
qDebug() << "WebSocket connected";
connect(&m_webSocket, &QWebSocket::textMessageReceived,
this, &SslEchoClient::onTextMessageReceived);
m_webSocket.sendTextMessage(QStringLiteral("Hello, world!"));
}
void SslEchoClient::onTextMessageReceived(QString message)
{
qDebug() << "Message received:" << message;
qApp->quit();
}
void SslEchoClient::onSslErrors(const QList<QSslError> &errors)
{
Q_UNUSED(errors);
m_webSocket.ignoreSslErrors();
}