summaryrefslogtreecommitdiff
path: root/examples/websockets
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2015-02-24 12:21:34 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2015-02-24 12:21:34 +0000
commitb01068a406f6ebf51e103dd541f36fd6ef144805 (patch)
tree9a1d2d634ce28672a72dfd1c7565f95cc82c2cb4 /examples/websockets
parent9989055693ac6225ae3e6f8153862765b0cd5e7e (diff)
parentb797778da01f72e64cda8680f29f3fa8434ffb0a (diff)
downloadqtwebsockets-b01068a406f6ebf51e103dd541f36fd6ef144805.tar.gz
Merge "Merge remote-tracking branch 'origin/5.4' into 5.5" into refs/staging/5.5
Diffstat (limited to 'examples/websockets')
-rw-r--r--examples/websockets/doc/echoserver.qdoc9
-rw-r--r--examples/websockets/doc/images/echoclient-html-example.pngbin0 -> 47215 bytes
-rw-r--r--examples/websockets/echoclient/echoclient.cpp13
-rw-r--r--examples/websockets/echoclient/echoclient.h3
-rw-r--r--examples/websockets/echoclient/main.cpp15
5 files changed, 33 insertions, 7 deletions
diff --git a/examples/websockets/doc/echoserver.qdoc b/examples/websockets/doc/echoserver.qdoc
index 1696589..e547e2a 100644
--- a/examples/websockets/doc/echoserver.qdoc
+++ b/examples/websockets/doc/echoserver.qdoc
@@ -39,7 +39,14 @@
sends back the messages it receives.
The Echo Server Example shows how to create a simple server application that
- sends back the messages it receives, using the WebSocket API.
+ sends back the messages it receives, using the \l {Qt WebSockets}{WebSocket} API.
+
+ If your web browser supports \l {Qt WebSockets}{WebSocket}, you can also use it
+ to open the \l {echoserver/echoclient.html}{echoclient.html} file, and operate
+ like the following screenshot.
+
+ \image echoclient-html-example.png Screenshot of the HTML version of Echo
+ Client example
\sa {Echo Client Example}
*/
diff --git a/examples/websockets/doc/images/echoclient-html-example.png b/examples/websockets/doc/images/echoclient-html-example.png
new file mode 100644
index 0000000..2cda8fd
--- /dev/null
+++ b/examples/websockets/doc/images/echoclient-html-example.png
Binary files differ
diff --git a/examples/websockets/echoclient/echoclient.cpp b/examples/websockets/echoclient/echoclient.cpp
index daccbfb..c666c6e 100644
--- a/examples/websockets/echoclient/echoclient.cpp
+++ b/examples/websockets/echoclient/echoclient.cpp
@@ -36,10 +36,13 @@
QT_USE_NAMESPACE
//! [constructor]
-EchoClient::EchoClient(const QUrl &url, QObject *parent) :
+EchoClient::EchoClient(const QUrl &url, bool debug, QObject *parent) :
QObject(parent),
- m_url(url)
+ m_url(url),
+ m_debug(debug)
{
+ if (m_debug)
+ qDebug() << "WebSocket server:" << url;
connect(&m_webSocket, &QWebSocket::connected, this, &EchoClient::onConnected);
connect(&m_webSocket, &QWebSocket::disconnected, this, &EchoClient::closed);
m_webSocket.open(QUrl(url));
@@ -49,7 +52,8 @@ EchoClient::EchoClient(const QUrl &url, QObject *parent) :
//! [onConnected]
void EchoClient::onConnected()
{
- qDebug() << "WebSocket connected";
+ if (m_debug)
+ qDebug() << "WebSocket connected";
connect(&m_webSocket, &QWebSocket::textMessageReceived,
this, &EchoClient::onTextMessageReceived);
m_webSocket.sendTextMessage(QStringLiteral("Hello, world!"));
@@ -59,7 +63,8 @@ void EchoClient::onConnected()
//! [onTextMessageReceived]
void EchoClient::onTextMessageReceived(QString message)
{
- qDebug() << "Message received:" << message;
+ if (m_debug)
+ qDebug() << "Message received:" << message;
m_webSocket.close();
}
//! [onTextMessageReceived]
diff --git a/examples/websockets/echoclient/echoclient.h b/examples/websockets/echoclient/echoclient.h
index 757c56d..165087b 100644
--- a/examples/websockets/echoclient/echoclient.h
+++ b/examples/websockets/echoclient/echoclient.h
@@ -40,7 +40,7 @@ class EchoClient : public QObject
{
Q_OBJECT
public:
- explicit EchoClient(const QUrl &url, QObject *parent = Q_NULLPTR);
+ explicit EchoClient(const QUrl &url, bool debug = false, QObject *parent = Q_NULLPTR);
Q_SIGNALS:
void closed();
@@ -52,6 +52,7 @@ private Q_SLOTS:
private:
QWebSocket m_webSocket;
QUrl m_url;
+ bool m_debug;
};
#endif // ECHOCLIENT_H
diff --git a/examples/websockets/echoclient/main.cpp b/examples/websockets/echoclient/main.cpp
index 91a2535..36157de 100644
--- a/examples/websockets/echoclient/main.cpp
+++ b/examples/websockets/echoclient/main.cpp
@@ -31,12 +31,25 @@
**
****************************************************************************/
#include <QtCore/QCoreApplication>
+#include <QtCore/QCommandLineParser>
+#include <QtCore/QCommandLineOption>
#include "echoclient.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
- EchoClient client(QUrl(QStringLiteral("ws://localhost:1234")));
+
+ QCommandLineParser parser;
+ parser.setApplicationDescription("QtWebSockets example: echoclient");
+ parser.addHelpOption();
+
+ QCommandLineOption dbgOption(QStringList() << "d" << "debug",
+ QCoreApplication::translate("main", "Debug output [default: off]."));
+ parser.addOption(dbgOption);
+ parser.process(a);
+ bool debug = parser.isSet(dbgOption);
+
+ EchoClient client(QUrl(QStringLiteral("ws://localhost:1234")), debug);
QObject::connect(&client, &EchoClient::closed, &a, &QCoreApplication::quit);
return a.exec();