summaryrefslogtreecommitdiff
path: root/examples/websockets/echoclient
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@digia.com>2014-03-19 16:45:42 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-19 17:52:08 +0100
commitfd65264aca55e599e94326311032b2075f60e6d7 (patch)
treef924989e4805ee1bf79359b40120b4db1a410459 /examples/websockets/echoclient
parentff4fb490dee278dd95afa31d0c35172804cb8dc2 (diff)
downloadqtwebsockets-fd65264aca55e599e94326311032b2075f60e6d7.tar.gz
Move examples into 'websockets' folder
In the packaging process the content of all 'examples' folders are copied together into one folder ... so modules are supposed to have their submodule name as a sub-folder of 'examples'. Change-Id: I9981b914e8268c932ca5a3d1c9fa73f8db0b6a5b Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>
Diffstat (limited to 'examples/websockets/echoclient')
-rw-r--r--examples/websockets/echoclient/echoclient.cpp73
-rw-r--r--examples/websockets/echoclient/echoclient.h65
-rw-r--r--examples/websockets/echoclient/echoclient.pro15
-rw-r--r--examples/websockets/echoclient/main.cpp51
4 files changed, 204 insertions, 0 deletions
diff --git a/examples/websockets/echoclient/echoclient.cpp b/examples/websockets/echoclient/echoclient.cpp
new file mode 100644
index 0000000..9e8ba9b
--- /dev/null
+++ b/examples/websockets/echoclient/echoclient.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Kurt Pattyn <pattyn.kurt@gmail.com>.
+** 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 "echoclient.h"
+#include <QtCore/QDebug>
+
+QT_USE_NAMESPACE
+
+//! [constructor]
+EchoClient::EchoClient(const QUrl &url, QObject *parent) :
+ QObject(parent),
+ m_url(url)
+{
+ connect(&m_webSocket, &QWebSocket::connected, this, &EchoClient::onConnected);
+ connect(&m_webSocket, &QWebSocket::disconnected, this, &EchoClient::closed);
+ m_webSocket.open(QUrl(url));
+}
+//! [constructor]
+
+//! [onConnected]
+void EchoClient::onConnected()
+{
+ qDebug() << "Websocket connected";
+ connect(&m_webSocket, &QWebSocket::textMessageReceived,
+ this, &EchoClient::onTextMessageReceived);
+ m_webSocket.sendTextMessage(QStringLiteral("Hello, world!"));
+}
+//! [onConnected]
+
+//! [onTextMessageReceived]
+void EchoClient::onTextMessageReceived(QString message)
+{
+ qDebug() << "Message received:" << message;
+ m_webSocket.close();
+}
+//! [onTextMessageReceived]
diff --git a/examples/websockets/echoclient/echoclient.h b/examples/websockets/echoclient/echoclient.h
new file mode 100644
index 0000000..b5a7709
--- /dev/null
+++ b/examples/websockets/echoclient/echoclient.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Kurt Pattyn <pattyn.kurt@gmail.com>.
+** 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 ECHOCLIENT_H
+#define ECHOCLIENT_H
+
+#include <QtCore/QObject>
+#include <QtWebSockets/QWebSocket>
+
+class EchoClient : public QObject
+{
+ Q_OBJECT
+public:
+ explicit EchoClient(const QUrl &url, QObject *parent = Q_NULLPTR);
+
+Q_SIGNALS:
+ void closed();
+
+private Q_SLOTS:
+ void onConnected();
+ void onTextMessageReceived(QString message);
+
+private:
+ QWebSocket m_webSocket;
+ QUrl m_url;
+};
+
+#endif // ECHOCLIENT_H
diff --git a/examples/websockets/echoclient/echoclient.pro b/examples/websockets/echoclient/echoclient.pro
new file mode 100644
index 0000000..24848e7
--- /dev/null
+++ b/examples/websockets/echoclient/echoclient.pro
@@ -0,0 +1,15 @@
+QT += core websockets
+QT -= gui
+
+TARGET = echoclient
+CONFIG += console
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+SOURCES += \
+ main.cpp \
+ echoclient.cpp
+
+HEADERS += \
+ echoclient.h
diff --git a/examples/websockets/echoclient/main.cpp b/examples/websockets/echoclient/main.cpp
new file mode 100644
index 0000000..fccaed1
--- /dev/null
+++ b/examples/websockets/echoclient/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Kurt Pattyn <pattyn.kurt@gmail.com>.
+** 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 "echoclient.h"
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication a(argc, argv);
+ EchoClient client(QUrl(QStringLiteral("ws://localhost:1234")));
+ QObject::connect(&client, &EchoClient::closed, &a, &QCoreApplication::quit);
+
+ return a.exec();
+}