summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-06-29 20:24:40 +0200
committerLiang Qi <liang.qi@theqtcompany.com>2015-06-30 16:26:08 +0200
commitc55e385f1f70f11d3ffd0f8372ccb8e7405018c5 (patch)
treea04c2e84b43830ecf9c8817f830055bfcf64cc0d /src
parenta3e0fe474c20eb526af9668c5cc97cf7055c77fa (diff)
parent086f3722777ee61f3c019ca064d4a844cf0f6fe4 (diff)
downloadqtwebsockets-c55e385f1f70f11d3ffd0f8372ccb8e7405018c5.tar.gz
Merge remote-tracking branch 'origin/5.5' into dev
Conflicts: .qmake.conf src/websockets/qwebsocket_p.cpp Change-Id: Ibcc1898263cc8bc80066370f045df6a217e46574
Diffstat (limited to 'src')
-rw-r--r--src/imports/qmlwebsockets/plugins.qmltypes5
-rw-r--r--src/imports/qmlwebsockets_compat/plugins.qmltypes97
-rw-r--r--src/imports/qmlwebsockets_compat/qmldir4
-rw-r--r--src/websockets/doc/images/websockets-pictorial-representation.jpgbin0 -> 39914 bytes
-rw-r--r--src/websockets/doc/qtwebsockets.qdocconf6
-rw-r--r--src/websockets/doc/src/index.qdoc29
-rw-r--r--src/websockets/doc/src/overview.qdoc112
-rw-r--r--src/websockets/doc/src/qtwebsockets-module.qdoc5
-rw-r--r--src/websockets/qwebsocket_p.cpp6
-rw-r--r--src/websockets/qwebsocketserver_p.cpp16
10 files changed, 260 insertions, 20 deletions
diff --git a/src/imports/qmlwebsockets/plugins.qmltypes b/src/imports/qmlwebsockets/plugins.qmltypes
index 5b8d1f9..5df4b5c 100644
--- a/src/imports/qmlwebsockets/plugins.qmltypes
+++ b/src/imports/qmlwebsockets/plugins.qmltypes
@@ -1,4 +1,4 @@
-import QtQuick.tooling 1.1
+import QtQuick.tooling 1.2
// This file describes the plugin-supplied types contained in the library.
// It is used for QML tooling purposes only.
@@ -7,6 +7,7 @@ import QtQuick.tooling 1.1
// 'qmlplugindump -notrelocatable QtWebSockets 1.0'
Module {
+ dependencies: []
Component {
name: "QQmlWebSocket"
prototype: "QObject"
@@ -51,7 +52,7 @@ Module {
Component {
name: "QQmlWebSocketServer"
prototype: "QObject"
- exports: ["Qt.WebSockets/WebSocketServer 1.0"]
+ exports: ["QtWebSockets/WebSocketServer 1.0"]
exportMetaObjectRevisions: [0]
Property { name: "url"; type: "QUrl"; isReadonly: true }
Property { name: "host"; type: "string" }
diff --git a/src/imports/qmlwebsockets_compat/plugins.qmltypes b/src/imports/qmlwebsockets_compat/plugins.qmltypes
new file mode 100644
index 0000000..ff8d976
--- /dev/null
+++ b/src/imports/qmlwebsockets_compat/plugins.qmltypes
@@ -0,0 +1,97 @@
+import QtQuick.tooling 1.2
+
+// This file describes the plugin-supplied types contained in the library.
+// It is used for QML tooling purposes only.
+//
+// This file was auto-generated by:
+// 'qmlplugindump -notrelocatable Qt.WebSockets 1.0'
+
+Module {
+ dependencies: []
+ Component {
+ name: "QQmlWebSocket"
+ prototype: "QObject"
+ exports: ["Qt.WebSockets/WebSocket 1.0"]
+ exportMetaObjectRevisions: [0]
+ Enum {
+ name: "Status"
+ values: {
+ "Connecting": 0,
+ "Open": 1,
+ "Closing": 2,
+ "Closed": 3,
+ "Error": 4
+ }
+ }
+ Property { name: "url"; type: "QUrl" }
+ Property { name: "status"; type: "Status"; isReadonly: true }
+ Property { name: "errorString"; type: "string"; isReadonly: true }
+ Property { name: "active"; type: "bool" }
+ Signal {
+ name: "textMessageReceived"
+ Parameter { name: "message"; type: "string" }
+ }
+ Signal {
+ name: "statusChanged"
+ Parameter { name: "status"; type: "Status" }
+ }
+ Signal {
+ name: "activeChanged"
+ Parameter { name: "isActive"; type: "bool" }
+ }
+ Signal {
+ name: "errorStringChanged"
+ Parameter { name: "errorString"; type: "string" }
+ }
+ Method {
+ name: "sendTextMessage"
+ type: "qlonglong"
+ Parameter { name: "message"; type: "string" }
+ }
+ }
+ Component {
+ name: "QQmlWebSocketServer"
+ prototype: "QObject"
+ exports: ["Qt.WebSockets/WebSocketServer 1.0"]
+ exportMetaObjectRevisions: [0]
+ Property { name: "url"; type: "QUrl"; isReadonly: true }
+ Property { name: "host"; type: "string" }
+ Property { name: "port"; type: "ushort" }
+ Property { name: "name"; type: "string" }
+ Property { name: "errorString"; type: "string"; isReadonly: true }
+ Property { name: "listen"; type: "bool" }
+ Property { name: "accept"; type: "bool" }
+ Signal {
+ name: "clientConnected"
+ Parameter { name: "webSocket"; type: "QQmlWebSocket"; isPointer: true }
+ }
+ Signal {
+ name: "errorStringChanged"
+ Parameter { name: "errorString"; type: "string" }
+ }
+ Signal {
+ name: "urlChanged"
+ Parameter { name: "url"; type: "QUrl" }
+ }
+ Signal {
+ name: "portChanged"
+ Parameter { name: "port"; type: "ushort" }
+ }
+ Signal {
+ name: "nameChanged"
+ Parameter { name: "name"; type: "string" }
+ }
+ Signal {
+ name: "hostChanged"
+ Parameter { name: "host"; type: "string" }
+ }
+ Signal {
+ name: "listenChanged"
+ Parameter { name: "listen"; type: "bool" }
+ }
+ Signal {
+ name: "acceptChanged"
+ Parameter { name: "accept"; type: "bool" }
+ }
+ }
+}
diff --git a/src/imports/qmlwebsockets_compat/qmldir b/src/imports/qmlwebsockets_compat/qmldir
index 8541103..a4310d9 100644
--- a/src/imports/qmlwebsockets_compat/qmldir
+++ b/src/imports/qmlwebsockets_compat/qmldir
@@ -1,4 +1,4 @@
module Qt.WebSockets
-plugin ../../QtWebSockets/declarative_qmlwebsockets
+plugin declarative_qmlwebsockets ../../QtWebSockets/
classname QtWebSocketsDeclarativeModule
-typeinfo ../../QtWebSockets/plugins.qmltypes
+typeinfo plugins.qmltypes
diff --git a/src/websockets/doc/images/websockets-pictorial-representation.jpg b/src/websockets/doc/images/websockets-pictorial-representation.jpg
new file mode 100644
index 0000000..5308fdd
--- /dev/null
+++ b/src/websockets/doc/images/websockets-pictorial-representation.jpg
Binary files differ
diff --git a/src/websockets/doc/qtwebsockets.qdocconf b/src/websockets/doc/qtwebsockets.qdocconf
index 2e1e15b..002898c 100644
--- a/src/websockets/doc/qtwebsockets.qdocconf
+++ b/src/websockets/doc/qtwebsockets.qdocconf
@@ -44,7 +44,8 @@ headerdirs += .. \
sourcedirs += .. \
src \
- ../../imports
+ ../../imports \
+ ../../../tests/doc
exampledirs += ../../../examples/websockets \
@@ -52,7 +53,8 @@ exampledirs += ../../../examples/websock
examples.fileextensions += "*.html"
-imagedirs += ../../../examples/websockets/doc/images
+imagedirs += ../../../examples/websockets/doc/images \
+ images
manifestmeta.thumbnail.names += "QtWebSockets/*"
diff --git a/src/websockets/doc/src/index.qdoc b/src/websockets/doc/src/index.qdoc
index 0d28036..e0f219c 100644
--- a/src/websockets/doc/src/index.qdoc
+++ b/src/websockets/doc/src/index.qdoc
@@ -37,11 +37,9 @@
the solution for applications that struggle to get real-time data feeds
with less network latency and minimum data exchange.
- The Qt WebSockets module implements the WebSocket protocol as specified in
- \l {http://tools.ietf.org/html/rfc6455} {RFC 6455}. It provides C++ and QML
- interfaces that enable Qt applications to act as a server that can process
- WebSocket-based requests, or a client that can consume data received from
- the server, or both.
+ The Qt WebSockets module provides C++ and QML interfaces that enable
+ Qt applications to act as a server that can process WebSocket requests,
+ or a client that can consume data received from the server, or both.
To use this module in your application, use the following include
statement:
@@ -57,8 +55,9 @@
QT += websockets
\endcode
- \section1 Reference documentation
+ \section1 Reference Documentation
\list
+ \li \l{Qt WebSockets Overview}{Overview}
\li \l{Qt WebSockets C++ Classes}{C++ Classes}
\li \l{Qt WebSockets QML Types}{QML Types}
\endlist
@@ -67,4 +66,22 @@
The module provides the following \l{Qt WebSockets Examples}{Examples} as a guide to using
the API.
+
+ \section1 Conformance
+ \list
+ \li \l {Testing Qt WebSockets}
+ \endlist
+*/
+
+/*!
+ \page qtwebsockets-testing.html
+ \title Testing Qt WebSockets
+
+ \l {http://autobahn.ws/testsuite/}{Autobahn|Testsuite}, a standard test
+ suite for WebSocket Protocol (RFC 6455), can be used for testing the
+ conformance of Qt WebSockets. Refer to Autobahn|Testsuite
+ \l {http://autobahn.ws/testsuite/installation.html}{installation documentation}
+ to set up the test suite.
+
+ \include README testsuite
*/
diff --git a/src/websockets/doc/src/overview.qdoc b/src/websockets/doc/src/overview.qdoc
new file mode 100644
index 0000000..df080c1
--- /dev/null
+++ b/src/websockets/doc/src/overview.qdoc
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** 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 The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+\page websockets-overview.html
+\title Qt WebSockets Overview
+\brief Provides insight into the WebSocket protocol and the Qt WebSockets module.
+
+Qt WebSockets enables you to build WebSocket-aware applications. It
+provides an implementation for the WebSocket protocol, which is offered by IETF
+(Internet Engineering Task Force) as a better alternative for bidirectional
+communication using the existing web infrastructure.
+
+Historically, web applications that needed bidirectional communication or
+push notifications had to use one of the HTTP-based solutions available. These
+solutions employed different techniques such as polling, long-polling, and
+streaming, to overcome the limitations of HTTP protocol, which is not designed
+for such use cases. As a result, high network latency, unnecessary data
+exchange, and stale or old data. The WebSocket offering by IETF helps to
+overcome these problems to a large extent.
+
+\section1 How does it Work?
+
+\image websockets-pictorial-representation.jpg
+
+As you can see in the pictorial representation, WebSocket-based solution
+consists of a client-side and server-side. The native client-side support for
+WebSocket is available on most of the popular web browsers such as Google
+Chrome, Internet Explorer, Safari, and so on. The server-side support for
+WebSocket makes it a complete solution, enabling bidirectional communication.
+Any browser with native WebSocket support should let you run a simple HTML and
+JavaScript-based client application using the HTML5 WebSocket API.
+
+A WebSocket connection begins with a initial HTTP-compatible handshake,
+which ensures backwards compatibility so that the WebSocket connections can
+share the default HTTP (80) and HTTPS (443) ports. On successful handshake,
+the connection is open for data exchange, until one of the two entities end
+the connection.
+
+The WebSocket protocol uses \c ws: and \c wss: URL schemes to represent
+unsecure and secure WebSocket requests, respectively. During the initial
+handshake, if a proxy server is detected, the protocol tries to set up a tunnel
+by issuing an \c{HTTP CONNECT} statement to the proxy. The tunnel approach to
+handle proxies is used irrespective of the request type, although it is proved
+to work better with TLS (Transport Layer Security) in secure connections.
+
+\section1 Typical Use Cases
+
+WebSocket suits best for scenarios where,
+\list
+ \li data presented must be up-to-date,
+ \li low network latency and minimal data exchange is crucial.
+\endlist
+
+A few example applications where we struggle to achieve these using the
+traditional approach are, instant messaging, online gaming, online stock
+trading, and so on.
+
+\section1 Role of Qt WebSockets
+
+The Qt WebSockets module provides APIs to develop WebSocket-based server and
+client applications. An example of where these APIs can be used is a server
+application that provides stock data, and a client application that registers
+for push notification when there is a change in price of a few stocks.
+
+The module provides both C++ and QML versions of the API, so you can choose
+the alternative that suits your need.
+
+\section2 Qt WebSockets with Qt Cloud Services
+
+The client application usually depends on an external service for data. Most of
+these service providers do not support WebSocket yet, so you end up developing
+a WebSocket-aware server application to bridge the gap. You can choose to run
+the server on an enterprise WebSocket gateway service such as Qt Cloud
+Services, avoiding the hassle of maintaining the necessary infrastructure
+required to host such a service.
+
+The Qt Cloud Services provides a Managed Application Runtime (MAR) backend,
+which enables deploying and running an instance of server application on the
+cloud. The server instance running on MAR gets a WebSocket URL, which can be
+used by the client applications to connect and receive data.
+
+\section2 Related Information
+\list
+\li \l {http://tools.ietf.org/html/rfc6455}{WebSocket RFC 6455}
+\li \l {https://qtcloudservices.com}{Qt Cloud Services}
+\endlist
+*/
diff --git a/src/websockets/doc/src/qtwebsockets-module.qdoc b/src/websockets/doc/src/qtwebsockets-module.qdoc
index acbe2ac..6c717f4 100644
--- a/src/websockets/doc/src/qtwebsockets-module.qdoc
+++ b/src/websockets/doc/src/qtwebsockets-module.qdoc
@@ -58,4 +58,9 @@
\code
import QtWebSockets 1.0
\endcode
+
+ \note Prior to Qt 5.5, the import statement was \c{import Qt.WebSockets 1.0}
+ (notice the dot between \c Qt and \c WebSockets). The old statement is still
+ supported for backwards compatibility, but it cannot be mixed with the new
+ statement within the same project.
*/
diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp
index 3ed8d8d..b9504f8 100644
--- a/src/websockets/qwebsocket_p.cpp
+++ b/src/websockets/qwebsocket_p.cpp
@@ -1045,6 +1045,10 @@ void QWebSocketPrivate::processStateChanged(QAbstractSocket::SocketState socketS
Q_ASSERT(m_pSocket);
Q_Q(QWebSocket);
QAbstractSocket::SocketState webSocketState = this->state();
+ int port = 80;
+ if (m_request.url().scheme() == QStringLiteral("wss"))
+ port = 443;
+
switch (socketState) {
case QAbstractSocket::ConnectedState:
if (webSocketState == QAbstractSocket::ConnectingState) {
@@ -1059,7 +1063,7 @@ void QWebSocketPrivate::processStateChanged(QAbstractSocket::SocketState socketS
createHandShakeRequest(m_resourceName,
m_request.url().host()
% QStringLiteral(":")
- % QString::number(m_request.url().port(80)),
+ % QString::number(m_request.url().port(port)),
origin(),
QString(),
QString(),
diff --git a/src/websockets/qwebsocketserver_p.cpp b/src/websockets/qwebsocketserver_p.cpp
index 73ca9d7..bc23674 100644
--- a/src/websockets/qwebsocketserver_p.cpp
+++ b/src/websockets/qwebsocketserver_p.cpp
@@ -370,13 +370,15 @@ void QWebSocketServerPrivate::setError(QWebSocketProtocol::CloseCode code, const
*/
void QWebSocketServerPrivate::onNewConnection()
{
- QTcpSocket *pTcpSocket = m_pTcpServer->nextPendingConnection();
- //use a queued connection because a QSslSocket
- //needs the event loop to process incoming data
- //if not queued, data is incomplete when handshakeReceived is called
- QObjectPrivate::connect(pTcpSocket, &QTcpSocket::readyRead,
- this, &QWebSocketServerPrivate::handshakeReceived,
- Qt::QueuedConnection);
+ while (m_pTcpServer->hasPendingConnections()) {
+ QTcpSocket *pTcpSocket = m_pTcpServer->nextPendingConnection();
+ //use a queued connection because a QSslSocket
+ //needs the event loop to process incoming data
+ //if not queued, data is incomplete when handshakeReceived is called
+ QObjectPrivate::connect(pTcpSocket, &QTcpSocket::readyRead,
+ this, &QWebSocketServerPrivate::handshakeReceived,
+ Qt::QueuedConnection);
+ }
}
/*!