summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorKurt Pattyn <pattyn.kurt@gmail.com>2013-11-06 20:00:39 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-06 20:02:37 +0100
commit91f93d2781e494d7835385aa501667d71ae231e7 (patch)
tree5eb0055dd628942073c7291249e93542f84f899c /examples
parent529b9a7cc85f63966c8ed6150ea18286b7459b1e (diff)
downloadqtwebsockets-91f93d2781e494d7835385aa501667d71ae231e7.tar.gz
Add sslEchoClient and sslEchoServer examples
Add license headers Change-Id: Ied74cb3db6ceed6c3f361e4afac860a7a3fb7676 Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/echoclient/echoclient.cpp2
-rw-r--r--examples/echoclient/echoclient.h4
-rw-r--r--examples/echoclient/main.cpp2
-rw-r--r--examples/echoserver/echoserver.cpp8
-rw-r--r--examples/echoserver/echoserver.h10
-rw-r--r--examples/echoserver/main.cpp2
-rw-r--r--examples/examples.pro2
-rw-r--r--examples/sslechoclient/main.cpp53
-rw-r--r--examples/sslechoclient/sslechoclient.cpp70
-rw-r--r--examples/sslechoclient/sslechoclient.h67
-rw-r--r--examples/sslechoclient/sslechoclient.pro15
-rw-r--r--examples/sslechoserver/localhost.cert18
-rw-r--r--examples/sslechoserver/localhost.key27
-rw-r--r--examples/sslechoserver/main.cpp52
-rw-r--r--examples/sslechoserver/sslechoclient.html102
-rw-r--r--examples/sslechoserver/sslechoserver.cpp131
-rw-r--r--examples/sslechoserver/sslechoserver.h70
-rw-r--r--examples/sslechoserver/sslechoserver.pro17
18 files changed, 638 insertions, 14 deletions
diff --git a/examples/echoclient/echoclient.cpp b/examples/echoclient/echoclient.cpp
index e487ed6..9dab2cb 100644
--- a/examples/echoclient/echoclient.cpp
+++ b/examples/echoclient/echoclient.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
#include "echoclient.h"
-#include <QDebug>
+#include <QtCore/QDebug>
QT_USE_NAMESPACE
diff --git a/examples/echoclient/echoclient.h b/examples/echoclient/echoclient.h
index 3bc1162..02592d9 100644
--- a/examples/echoclient/echoclient.h
+++ b/examples/echoclient/echoclient.h
@@ -41,10 +41,10 @@
#ifndef ECHOCLIENT_H
#define ECHOCLIENT_H
-#include <QObject>
+#include <QtCore/QObject>
#include <QtWebSockets/QWebSocket>
-QT_FORWARD_DECLARE_CLASS(QWebSocket);
+QT_FORWARD_DECLARE_CLASS(QWebSocket)
class EchoClient : public QObject
{
diff --git a/examples/echoclient/main.cpp b/examples/echoclient/main.cpp
index 5226853..d93fd24 100644
--- a/examples/echoclient/main.cpp
+++ b/examples/echoclient/main.cpp
@@ -38,7 +38,7 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include <QCoreApplication>
+#include <QtCore/QCoreApplication>
#include "echoclient.h"
int main(int argc, char *argv[])
diff --git a/examples/echoserver/echoserver.cpp b/examples/echoserver/echoserver.cpp
index 78e99b9..0825f5d 100644
--- a/examples/echoserver/echoserver.cpp
+++ b/examples/echoserver/echoserver.cpp
@@ -39,9 +39,9 @@
**
****************************************************************************/
#include "echoserver.h"
-#include "qwebsocketserver.h"
-#include "qwebsocket.h"
-#include <QDebug>
+#include "QtWebSockets/qwebsocketserver.h"
+#include "QtWebSockets/qwebsocket.h"
+#include <QtCore/QDebug>
QT_USE_NAMESPACE
@@ -51,7 +51,7 @@ EchoServer::EchoServer(quint16 port, QObject *parent) :
m_pWebSocketServer(Q_NULLPTR),
m_clients()
{
- m_pWebSocketServer = new QWebSocketServer("Echo Server", this);
+ m_pWebSocketServer = new QWebSocketServer("Echo Server", QWebSocketServer::NON_SECURE_MODE, this);
if (m_pWebSocketServer->listen(QHostAddress::Any, port))
{
qDebug() << "Echoserver listening on port" << port;
diff --git a/examples/echoserver/echoserver.h b/examples/echoserver/echoserver.h
index bbfa9e0..0333f8f 100644
--- a/examples/echoserver/echoserver.h
+++ b/examples/echoserver/echoserver.h
@@ -41,12 +41,12 @@
#ifndef ECHOSERVER_H
#define ECHOSERVER_H
-#include <QObject>
-#include <QList>
-#include <QByteArray>
+#include <QtCore/QObject>
+#include <QtCore/QList>
+#include <QtCore/QByteArray>
-QT_FORWARD_DECLARE_CLASS(QWebSocketServer);
-QT_FORWARD_DECLARE_CLASS(QWebSocket);
+QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
+QT_FORWARD_DECLARE_CLASS(QWebSocket)
class EchoServer : public QObject
{
diff --git a/examples/echoserver/main.cpp b/examples/echoserver/main.cpp
index c90e8c5..b424666 100644
--- a/examples/echoserver/main.cpp
+++ b/examples/echoserver/main.cpp
@@ -38,7 +38,7 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include <QCoreApplication>
+#include <QtCore/QCoreApplication>
#include "echoserver.h"
int main(int argc, char *argv[])
diff --git a/examples/examples.pro b/examples/examples.pro
index 6b2218c..2589298 100644
--- a/examples/examples.pro
+++ b/examples/examples.pro
@@ -2,5 +2,7 @@ TEMPLATE = subdirs
SUBDIRS = echoclient \
echoserver \
+ sslechoserver \
+ sslechoclient \
simplechat
qtHaveModule(quick): SUBDIRS += qmlwebsocketclient
diff --git a/examples/sslechoclient/main.cpp b/examples/sslechoclient/main.cpp
new file mode 100644
index 0000000..e324580
--- /dev/null
+++ b/examples/sslechoclient/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebSockets module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QtCore/QCoreApplication>
+#include "sslechoclient.h"
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication a(argc, argv);
+ //SslEchoClient client(QUrl("wss://localhost:1234"));
+ SslEchoClient client(QUrl("wss://echo.websocket.org"));
+
+ Q_UNUSED(client);
+
+ return a.exec();
+}
diff --git a/examples/sslechoclient/sslechoclient.cpp b/examples/sslechoclient/sslechoclient.cpp
new file mode 100644
index 0000000..7160442
--- /dev/null
+++ b/examples/sslechoclient/sslechoclient.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebSockets module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "sslechoclient.h"
+#include <QtCore/QDebug>
+
+QT_USE_NAMESPACE
+
+//! [constructor]
+SslEchoClient::SslEchoClient(const QUrl &url, QObject *parent) :
+ QObject(parent),
+ m_webSocket()
+{
+ connect(&m_webSocket, SIGNAL(connected()), this, SLOT(onConnected()));
+ m_webSocket.open(QUrl(url));
+}
+//! [constructor]
+
+//! [onConnected]
+void SslEchoClient::onConnected()
+{
+ qDebug() << "Websocket connected";
+ connect(&m_webSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(onTextMessageReceived(QString)));
+ m_webSocket.write("Hello, world!");
+}
+//! [onConnected]
+
+//! [onTextMessageReceived]
+void SslEchoClient::onTextMessageReceived(QString message)
+{
+ qDebug() << "Message received:" << message;
+}
+//! [onTextMessageReceived]
diff --git a/examples/sslechoclient/sslechoclient.h b/examples/sslechoclient/sslechoclient.h
new file mode 100644
index 0000000..db9d16d
--- /dev/null
+++ b/examples/sslechoclient/sslechoclient.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebSockets module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef SSLECHOCLIENT_H
+#define SSLECHOCLIENT_H
+
+#include <QtCore/QObject>
+#include <QtWebSockets/QWebSocket>
+
+QT_FORWARD_DECLARE_CLASS(QWebSocket)
+
+class SslEchoClient : public QObject
+{
+ Q_OBJECT
+public:
+ explicit SslEchoClient(const QUrl &url, QObject *parent = Q_NULLPTR);
+
+Q_SIGNALS:
+
+public Q_SLOTS:
+
+private Q_SLOTS:
+ void onConnected();
+ void onTextMessageReceived(QString message);
+
+private:
+ QWebSocket m_webSocket;
+};
+
+#endif // SSLECHOCLIENT_H
diff --git a/examples/sslechoclient/sslechoclient.pro b/examples/sslechoclient/sslechoclient.pro
new file mode 100644
index 0000000..431301f
--- /dev/null
+++ b/examples/sslechoclient/sslechoclient.pro
@@ -0,0 +1,15 @@
+QT += core websockets
+QT -= gui
+
+TARGET = sslechoclient
+CONFIG += console
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+SOURCES += \
+ main.cpp \
+ sslechoclient.cpp
+
+HEADERS += \
+ sslechoclient.h
diff --git a/examples/sslechoserver/localhost.cert b/examples/sslechoserver/localhost.cert
new file mode 100644
index 0000000..7aa33a1
--- /dev/null
+++ b/examples/sslechoserver/localhost.cert
@@ -0,0 +1,18 @@
+-----BEGIN CERTIFICATE-----
+MIIC+zCCAeOgAwIBAgIJAP26rumH9qOkMA0GCSqGSIb3DQEBBQUAMBQxEjAQBgNV
+BAMMCWxvY2FsaG9zdDAeFw0xMzExMDYxNjU4NTRaFw0yMzExMDQxNjU4NTRaMBQx
+EjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
+ggEBALgagHqEqWr4WH+MFBQE+BWZri5UUn/QPORN2pUB1lWMzeDCM5YMc/D1dhUG
+7zg5I9QO5Ut1YcoVO25OAseddgVaIFXPNyEG2nUTz53xx3pyqp3WtQkYCRAQzI8K
+IFIzBSD+nJNl+8gBld7Fe+4d8bFCwfXspQBJ2RY8SQ6tjRFVKHN7haLsD+WV3AFg
+siWkCxeXxVLNI69cuLwV7bEsv6U1N1yNROvRpu4yJcaNnu36kJFbORPhNfy6qJGX
+i0A30dYdMoLhtCN3Qf/XwGyS84Rs2XXduNlBdUgbpluY2r2x3Gz32hIwsHHcPzX6
+O9nwVPQ8k29lfC8yPmAWA9vPiBUCAwEAAaNQME4wHQYDVR0OBBYEFJZESCN01tY3
+MgXxmqiUBNPxsgiKMB8GA1UdIwQYMBaAFJZESCN01tY3MgXxmqiUBNPxsgiKMAwG
+A1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAHylCJYED9PqLB9FE4A0CRfy
+BdxIqOK+UExxxkU1DeN7kM4U2+E0G85nqBLOL34BDj8LDKJH9WC7L9jMV8T3Upbg
++RrTGiIcyjsL18L2KWeOia1R6VVAQcZrqoWv+QXyVvIi8IpTOE074C6+Vzx6XYMe
+CpW4jcdfmn39oVeMXxz9+8wD7CWeCT+SMj8tt+OB1XjQwdEG03vb6ArtnuJT77VI
+3I090OtKksBE5hy1H9N2E3wxhFTxC+DI5sc7Bj87v3blL4Z3DvRUEHwQHcDccQ0D
+ERUEcSyn1YGSlDVbVf3CzH4WXxddUBmaSHf4JTuAMy0C0A6IWuMP+rVVvVMIXNM=
+-----END CERTIFICATE-----
diff --git a/examples/sslechoserver/localhost.key b/examples/sslechoserver/localhost.key
new file mode 100644
index 0000000..dcc262c
--- /dev/null
+++ b/examples/sslechoserver/localhost.key
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEogIBAAKCAQEAuBqAeoSpavhYf4wUFAT4FZmuLlRSf9A85E3alQHWVYzN4MIz
+lgxz8PV2FQbvODkj1A7lS3VhyhU7bk4Cx512BVogVc83IQbadRPPnfHHenKqnda1
+CRgJEBDMjwogUjMFIP6ck2X7yAGV3sV77h3xsULB9eylAEnZFjxJDq2NEVUoc3uF
+ouwP5ZXcAWCyJaQLF5fFUs0jr1y4vBXtsSy/pTU3XI1E69Gm7jIlxo2e7fqQkVs5
+E+E1/LqokZeLQDfR1h0yguG0I3dB/9fAbJLzhGzZdd242UF1SBumW5javbHcbPfa
+EjCwcdw/Nfo72fBU9DyTb2V8LzI+YBYD28+IFQIDAQABAoIBADADmWZamuSvCEWb
+ftEJyrm3btneW/XBlV/lfhBGfmOpaTgo7dNARCyfl8A8Ir+DB3kSuXJIlsxhZTKL
+XeY5hsI2kyBN/o66ftbx57/FgsTIiv7HNEe+4P4zo2Xaujs12yyTuromatfqse97
+iaq8XIBibLt6kD3XBKrr5hHR6WyPW9F7sM91e/1OGTXBt9URvnnHqcimJ8Wvto5p
+SMFlud8JXMmARhWaIfqQIcNYmNEHea0LfOZVerTOPE7IZd5coM91mr71lzoxs9Ik
+bRMbqgyAMXEJV3ynEH2LjjJZo1bVb8Va45QqqOQ4FtL46n1Z+EVUXyhCHGepwyOv
+uAru0wECgYEA3CnM252417At+N9Zq4KtBJ8tIEXKqvK1Bl5aZSqaJClywjCttR2l
+lRAlIRAmqHCQuxLDDfLfiJh6xgZsjr4MhksuyKc7DKssfWW+XCd+5GaaMoMvJXhs
+caJdhNSHzpnLPi++tJBYHwHa354D5PJ3eItzLkmuVyhmc3plNbkBGLECgYEA1hIX
+mA9KadVG9VkaDci+xo1p0ACb5ccHAvmA8+fzb0H09yKw5bCSpNGeHj4Qv5ZFqsUm
+96NWYEB38ezupWqWMFd9zr1kD2s3r6Kpq1TS6xuDPapyiXaKpcH1ys7IWZkinCkN
+oxhPHcQbFu9/CN2zIVFKvF5P98Rh0+wO7fgL/qUCgYAyleAd7cVUuYQ2lIrz31iF
+oVUq/x4r3Qw+5Fr8t6cm++cEO08OODudXlJJoH5hYUu/z/XFNLKrne1Hpp42xe/2
+wzuCmvn0VTgpr8DnR6PeMrznMkEY6Oxxx46ZQIPbsnaCWVIGBsxYg4KYsqPObO+K
+YPAcCI3oNL4ldk/e4h0gYQKBgHm+4FxClfeKrEhs3DxqptUVJ9B8CC2t+3bdn1EX
+4YKs6DyFJkX7HetOq7ZXZf8P3583cOn1ovIquAyGy1KYQ8JKf+pMG9QJDip9QDGI
+lEvR4dn4ThuPp1qN7NPitl7+kIhvcKoI8TXkieOJYZ4ROAcCzJZErQYkUd7MqdD8
++RVhAoGAcWC9HRDhxjs4shaBlYi8Lfp3dV4f/4UgYosdFAZ26atwHz+sCLHwwg1j
+6t5Zxy9oEB89S5v5hkgO8//JmopvISSokdvocASMdKE+OmS3JfBmhQK9qVBW/vv/
+ut2bhPjEzIJyNFKX3xnGI8PREcR2eY+WLhIZ5KiR61tGpktJ4bg=
+-----END RSA PRIVATE KEY-----
diff --git a/examples/sslechoserver/main.cpp b/examples/sslechoserver/main.cpp
new file mode 100644
index 0000000..145e94d
--- /dev/null
+++ b/examples/sslechoserver/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebSockets module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QtCore/QCoreApplication>
+#include "sslechoserver.h"
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication a(argc, argv);
+ SslEchoServer server(1234);
+
+ Q_UNUSED(server);
+
+ return a.exec();
+}
diff --git a/examples/sslechoserver/sslechoclient.html b/examples/sslechoserver/sslechoclient.html
new file mode 100644
index 0000000..ddae9da
--- /dev/null
+++ b/examples/sslechoserver/sslechoclient.html
@@ -0,0 +1,102 @@
+<html>
+ <head>
+ <title>Websocket Echo Client</title>
+ </head>
+ <body>
+ <h1>Websocket Echo Client</h1>
+ <p>
+ <button onClick="initWebsocket();">Connect</button>
+ <button onClick="stopWebsocket();">Disconnect</button>
+ <button onClick="checkSocket();">State</button>
+ </p>
+ <p>
+ <textarea id="debugTextArea" style="width:400px;height:200px;"></textarea>
+ </p>
+ <p>
+ <input type="text" id="inputText" onkeydown="if(event.keyCode==13)sendMessage();"/>
+ <button onClick="sendMessage();">Send</button>
+ </p>
+
+ <script type="text/javascript">
+ var debugTextArea = document.getElementById("debugTextArea");
+ var wsUri = "wss://localhost:1234";
+ var websocket = null;
+
+ function debug(message) {
+ debugTextArea.value += message + "\n";
+ debugTextArea.scrollTop = debugTextArea.scrollHeight;
+ }
+
+ function sendMessage() {
+ var msg = document.getElementById("inputText").value;
+ if ( websocket != null )
+ {
+ document.getElementById("inputText").value = "";
+ websocket.send( msg );
+ console.log( "string sent :", '"'+msg+'"' );
+ }
+ }
+
+ function initWebsocket() {
+ try {
+ if (typeof MozWebSocket == 'function')
+ WebSocket = MozWebSocket;
+ if ( websocket && websocket.readyState == 1 )
+ websocket.close();
+ websocket = new WebSocket( wsUri );
+ websocket.onopen = function (evt) {
+ debug("CONNECTED");
+ };
+ websocket.onclose = function (evt) {
+ debug("DISCONNECTED");
+ };
+ websocket.onmessage = function (evt) {
+ console.log( "Message received :", evt.data );
+ debug( evt.data );
+ };
+ websocket.onerror = function (evt) {
+ debug('ERROR: ' + evt.data);
+ };
+ } catch (exception) {
+ debug('ERROR: ' + exception);
+ }
+ }
+
+ function stopWebsocket() {
+ if (websocket)
+ websocket.close();
+ }
+
+ function checkSocket() {
+ if (websocket != null) {
+ var stateStr;
+ switch (websocket.readyState) {
+ case 0: {
+ stateStr = "CONNECTING";
+ break;
+ }
+ case 1: {
+ stateStr = "OPEN";
+ break;
+ }
+ case 2: {
+ stateStr = "CLOSING";
+ break;
+ }
+ case 3: {
+ stateStr = "CLOSED";
+ break;
+ }
+ default: {
+ stateStr = "UNKNOW";
+ break;
+ }
+ }
+ debug("Websocket state = " + websocket.readyState + " ( " + stateStr + " )");
+ } else {
+ debug("Websocket is null");
+ }
+ }
+ </script>
+ </body>
+</html>
diff --git a/examples/sslechoserver/sslechoserver.cpp b/examples/sslechoserver/sslechoserver.cpp
new file mode 100644
index 0000000..d8cfe3b
--- /dev/null
+++ b/examples/sslechoserver/sslechoserver.cpp
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebSockets module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "sslechoserver.h"
+#include "QtWebSockets/QWebSocketServer"
+#include "QtWebSockets/QWebSocket"
+#include <QtCore/QDebug>
+#include <QtCore/QFile>
+#include <QtNetwork/QSslCertificate>
+#include <QtNetwork/QSslKey>
+
+QT_USE_NAMESPACE
+
+//! [constructor]
+SslEchoServer::SslEchoServer(quint16 port, QObject *parent) :
+ QObject(parent),
+ m_pWebSocketServer(Q_NULLPTR),
+ m_clients()
+{
+ m_pWebSocketServer = new QWebSocketServer("SSL Echo Server", QWebSocketServer::SECURE_MODE, this);
+ QSslConfiguration sslConfiguration;
+ QFile certFile(QStringLiteral("./localhost.cert"));
+ QFile keyFile(QStringLiteral("./localhost.key"));
+ certFile.open(QIODevice::ReadOnly);
+ keyFile.open(QIODevice::ReadOnly);
+ QSslCertificate certificate(&certFile, QSsl::Pem);
+ QSslKey sslKey(&keyFile, QSsl::Rsa, QSsl::Pem);
+ certFile.close();
+ keyFile.close();
+ sslConfiguration.setProtocol(QSsl::AnyProtocol);
+ sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone);
+ sslConfiguration.setLocalCertificate(certificate);
+ sslConfiguration.setPrivateKey(sslKey);
+ sslConfiguration.setProtocol(QSsl::TlsV1SslV3);
+ m_pWebSocketServer->setSslConfiguration(sslConfiguration);
+
+ if (m_pWebSocketServer->listen(QHostAddress::Any, port))
+ {
+ qDebug() << "SSL Echo Server listening on port" << port;
+ connect(m_pWebSocketServer, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
+ }
+}
+//! [constructor]
+
+//! [onNewConnection]
+void SslEchoServer::onNewConnection()
+{
+ QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection();
+
+ qDebug() << "Client connected:" << pSocket->peerName() << pSocket->origin();
+
+ connect(pSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(processMessage(QString)));
+ connect(pSocket, SIGNAL(binaryMessageReceived(QByteArray)), this, SLOT(processBinaryMessage(QByteArray)));
+ connect(pSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
+ //connect(pSocket, SIGNAL(pong(quint64)), this, SLOT(processPong(quint64)));
+
+ m_clients << pSocket;
+}
+//! [onNewConnection]
+
+//! [processMessage]
+void SslEchoServer::processMessage(QString message)
+{
+ QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
+ if (pClient)
+ {
+ pClient->write(message);
+ }
+}
+//! [processMessage]
+
+//! [processBinaryMessage]
+void SslEchoServer::processBinaryMessage(QByteArray message)
+{
+ QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
+ if (pClient)
+ {
+ pClient->write(message);
+ }
+}
+//! [processBinaryMessage]
+
+//! [socketDisconnected]
+void SslEchoServer::socketDisconnected()
+{
+ qDebug() << "Client disconnected";
+ QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
+ if (pClient)
+ {
+ m_clients.removeAll(pClient);
+ pClient->deleteLater();
+ }
+}
+//! [socketDisconnected]
diff --git a/examples/sslechoserver/sslechoserver.h b/examples/sslechoserver/sslechoserver.h
new file mode 100644
index 0000000..bbd0a87
--- /dev/null
+++ b/examples/sslechoserver/sslechoserver.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebSockets module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef SSLECHOSERVER_H
+#define SSLECHOSERVER_H
+
+#include <QtCore/QObject>
+#include <QtCore/QList>
+#include <QtCore/QByteArray>
+
+QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
+QT_FORWARD_DECLARE_CLASS(QWebSocket)
+
+class SslEchoServer : public QObject
+{
+ Q_OBJECT
+public:
+ explicit SslEchoServer(quint16 port, QObject *parent = Q_NULLPTR);
+
+Q_SIGNALS:
+
+private Q_SLOTS:
+ void onNewConnection();
+ void processMessage(QString message);
+ void processBinaryMessage(QByteArray message);
+ void socketDisconnected();
+
+private:
+ QWebSocketServer *m_pWebSocketServer;
+ QList<QWebSocket *> m_clients;
+};
+
+#endif //SSLECHOSERVER_H
diff --git a/examples/sslechoserver/sslechoserver.pro b/examples/sslechoserver/sslechoserver.pro
new file mode 100644
index 0000000..2663872
--- /dev/null
+++ b/examples/sslechoserver/sslechoserver.pro
@@ -0,0 +1,17 @@
+QT += core websockets
+QT -= gui
+
+TARGET = sslechoserver
+CONFIG += console
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+SOURCES += \
+ main.cpp \
+ sslechoserver.cpp
+
+HEADERS += \
+ sslechoserver.h
+
+OTHER_FILES += sslechoclient.html