summaryrefslogtreecommitdiff
path: root/examples/sslechoclient/sslechoclient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/sslechoclient/sslechoclient.cpp')
-rw-r--r--examples/sslechoclient/sslechoclient.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/examples/sslechoclient/sslechoclient.cpp b/examples/sslechoclient/sslechoclient.cpp
index fdf00df..037990d 100644
--- a/examples/sslechoclient/sslechoclient.cpp
+++ b/examples/sslechoclient/sslechoclient.cpp
@@ -40,6 +40,8 @@
****************************************************************************/
#include "sslechoclient.h"
#include <QtCore/QDebug>
+#include <QtWebSockets/QWebSocket>
+#include <QCoreApplication>
QT_USE_NAMESPACE
@@ -49,6 +51,9 @@ SslEchoClient::SslEchoClient(const QUrl &url, QObject *parent) :
m_webSocket()
{
connect(&m_webSocket, &QWebSocket::connected, this, &SslEchoClient::onConnected);
+ typedef void (QWebSocket:: *sslErrorsSignal)(const QList<QSslError> &);
+ connect(&m_webSocket, static_cast<sslErrorsSignal>(&QWebSocket::sslErrors),
+ this, &SslEchoClient::onSslErrors);
m_webSocket.open(QUrl(url));
}
//! [constructor]
@@ -67,5 +72,17 @@ void SslEchoClient::onConnected()
void SslEchoClient::onTextMessageReceived(QString message)
{
qDebug() << "Message received:" << message;
+ qApp->quit();
+}
+
+void SslEchoClient::onSslErrors(const QList<QSslError> &errors)
+{
+ Q_UNUSED(errors);
+
+ // WARNING: Never ignore SSL errors in production code.
+ // The proper way to handle self-signed certificates is to add a custom root
+ // to the CA store.
+
+ m_webSocket.ignoreSslErrors();
}
//! [onTextMessageReceived]