├── .cmake.conf ├── .gitreview ├── .tag ├── CMakeLists.txt ├── LICENSES ├── BSD-3-Clause.txt ├── GFDL-1.3-no-invariants-only.txt ├── GPL-2.0-only.txt ├── GPL-3.0-only.txt ├── LGPL-3.0-only.txt └── LicenseRef-Qt-Commercial.txt ├── README.md ├── REUSE.toml ├── coin ├── axivion │ └── ci_config_linux.json └── module_config.yaml ├── dependencies.yaml ├── dist ├── REUSE.toml ├── changes-5.10.0 ├── changes-5.10.1 ├── changes-5.11.0 ├── changes-5.11.1 ├── changes-5.11.2 ├── changes-5.11.3 ├── changes-5.12.0 ├── changes-5.12.1 ├── changes-5.12.2 ├── changes-5.12.3 ├── changes-5.12.4 ├── changes-5.12.5 ├── changes-5.13.0 ├── changes-5.13.1 ├── changes-5.13.2 ├── changes-5.14.0 ├── changes-5.14.1 ├── changes-5.14.2 ├── changes-5.15.0 ├── changes-5.15.1 ├── changes-5.15.2 ├── changes-5.5.0 ├── changes-5.6.3 ├── changes-5.7.0 ├── changes-5.8.0 ├── changes-5.9.0 ├── changes-5.9.1 ├── changes-5.9.2 ├── changes-5.9.3 ├── changes-5.9.4 ├── changes-5.9.5 └── changes-5.9.6 ├── examples ├── CMakeLists.txt ├── examples.pro └── websockets │ ├── CMakeLists.txt │ ├── doc │ ├── echoclient.qdoc │ ├── echoserver.qdoc │ ├── examples.qdoc │ ├── images │ │ ├── echoclient-console-example.webp │ │ ├── echoclient-html-example.png │ │ ├── qmlwebsocketclient-example.webp │ │ ├── qmlwebsocketserver-example.webp │ │ ├── simplechat-html-example.webp │ │ ├── sslechoclient-console-example.webp │ │ └── sslechoclient-html-example.webp │ ├── qmlwebsocketclient.qdoc │ ├── qmlwebsocketserver.qdoc │ ├── simplechat.qdoc │ ├── sslechoclient.qdoc │ └── sslechoserver.qdoc │ ├── echoclient │ ├── CMakeLists.txt │ ├── echoclient.cpp │ ├── echoclient.h │ ├── echoclient.pro │ └── main.cpp │ ├── echoserver │ ├── CMakeLists.txt │ ├── echoclient.html │ ├── echoserver.cpp │ ├── echoserver.h │ ├── echoserver.pro │ └── main.cpp │ ├── qmlwebsocketclient │ ├── CMakeLists.txt │ ├── data.qrc │ ├── main.cpp │ ├── qml │ │ └── qmlwebsocketclient │ │ │ └── main.qml │ └── qmlwebsocketclient.pro │ ├── qmlwebsocketserver │ ├── CMakeLists.txt │ ├── data.qrc │ ├── main.cpp │ ├── qml │ │ └── qmlwebsocketserver │ │ │ └── main.qml │ └── qmlwebsocketserver.pro │ ├── simplechat │ ├── CMakeLists.txt │ ├── chatclient.html │ ├── chatserver.cpp │ ├── chatserver.h │ ├── main.cpp │ └── simplechat.pro │ ├── sslechoclient │ ├── CMakeLists.txt │ ├── main.cpp │ ├── sslechoclient.cpp │ ├── sslechoclient.h │ └── sslechoclient.pro │ ├── sslechoserver │ ├── CMakeLists.txt │ ├── generate.sh │ ├── localhost.cert │ ├── localhost.key │ ├── main.cpp │ ├── securesocketclient.qrc │ ├── sslechoclient.html │ ├── sslechoserver.cpp │ ├── sslechoserver.h │ └── sslechoserver.pro │ └── websockets.pro ├── licenseRule.json ├── qtwebsockets.pro ├── src ├── CMakeLists.txt ├── imports │ ├── CMakeLists.txt │ └── qmlwebsockets │ │ ├── CMakeLists.txt │ │ ├── plugins.qmltypes │ │ ├── qmlwebsockets_plugin.cpp │ │ ├── qmlwebsockets_plugin.h │ │ ├── qqmlwebsocket.cpp │ │ ├── qqmlwebsocket.h │ │ ├── qqmlwebsocketserver.cpp │ │ └── qqmlwebsocketserver.h └── websockets │ ├── CMakeLists.txt │ ├── doc │ ├── images │ │ └── websockets-pictorial-representation.jpg │ ├── qtwebsockets.qdocconf │ ├── snippets │ │ └── src_websockets_ssl_qwebsocket.cpp │ └── src │ │ ├── external-resources.qdoc │ │ ├── index.qdoc │ │ ├── overview.qdoc │ │ ├── qt6-changes.qdoc │ │ ├── qtwebsockets-module.qdoc │ │ └── qtwebsockets-toc.qdoc │ ├── qdefaultmaskgenerator_p.cpp │ ├── qdefaultmaskgenerator_p.h │ ├── qmaskgenerator.cpp │ ├── qmaskgenerator.h │ ├── qwebsocket.cpp │ ├── qwebsocket.h │ ├── qwebsocket_p.cpp │ ├── qwebsocket_p.h │ ├── qwebsocket_wasm_p.cpp │ ├── qwebsocketcorsauthenticator.cpp │ ├── qwebsocketcorsauthenticator.h │ ├── qwebsocketcorsauthenticator_p.h │ ├── qwebsocketdataprocessor.cpp │ ├── qwebsocketdataprocessor_p.h │ ├── qwebsocketframe.cpp │ ├── qwebsocketframe_p.h │ ├── qwebsockethandshakeoptions.cpp │ ├── qwebsockethandshakeoptions.h │ ├── qwebsockethandshakeoptions_p.h │ ├── qwebsockethandshakerequest.cpp │ ├── qwebsockethandshakerequest_p.h │ ├── qwebsockethandshakeresponse.cpp │ ├── qwebsockethandshakeresponse_p.h │ ├── qwebsocketprotocol.cpp │ ├── qwebsocketprotocol.h │ ├── qwebsocketprotocol_p.h │ ├── qwebsockets_global.h │ ├── qwebsocketserver.cpp │ ├── qwebsocketserver.h │ ├── qwebsocketserver_p.cpp │ └── qwebsocketserver_p.h └── tests ├── CMakeLists.txt ├── auto ├── CMakeLists.txt ├── bic │ └── data │ │ ├── QtWebSockets.5.10.0.linux-gcc-amd64.txt │ │ ├── QtWebSockets.5.11.0.linux-gcc-amd64.txt │ │ ├── QtWebSockets.5.12.0.linux-gcc-amd64.txt │ │ ├── QtWebSockets.5.13.0.linux-gcc-amd64.txt │ │ ├── QtWebSockets.5.14.0.linux-gcc-amd64.txt │ │ ├── QtWebSockets.5.6.0.linux-gcc-amd64.txt │ │ ├── QtWebSockets.5.7.0.linux-gcc-amd64.txt │ │ ├── QtWebSockets.5.8.0.linux-gcc-amd64.txt │ │ └── QtWebSockets.5.9.0.linux-gcc-amd64.txt ├── cmake │ └── CMakeLists.txt ├── qml │ ├── CMakeLists.txt │ └── qmlwebsockets │ │ ├── CMakeLists.txt │ │ ├── tst_qmlwebsockets.cpp │ │ └── tst_qmlwebsockets.qml └── websockets │ ├── CMakeLists.txt │ ├── dataprocessor │ ├── CMakeLists.txt │ └── tst_dataprocessor.cpp │ ├── handshakerequest │ ├── CMakeLists.txt │ └── tst_handshakerequest.cpp │ ├── handshakeresponse │ ├── CMakeLists.txt │ └── tst_handshakeresponse.cpp │ ├── qdefaultmaskgenerator │ ├── CMakeLists.txt │ └── tst_defaultmaskgenerator.cpp │ ├── qwebsocket │ ├── CMakeLists.txt │ └── tst_qwebsocket.cpp │ ├── qwebsocketcorsauthenticator │ ├── CMakeLists.txt │ └── tst_qwebsocketcorsauthenticator.cpp │ ├── qwebsocketserver │ ├── BLACKLIST │ ├── CMakeLists.txt │ └── tst_qwebsocketserver.cpp │ ├── shared │ ├── localhost.cert │ └── localhost.key │ ├── websocketframe │ ├── CMakeLists.txt │ └── tst_websocketframe.cpp │ └── websocketprotocol │ ├── CMakeLists.txt │ └── tst_websocketprotocol.cpp ├── doc └── README.qdocinc ├── global └── global.cfg └── manual ├── compliance ├── compliance.pro └── tst_compliance.cpp ├── manual.pro └── websockets ├── tst_websockets.cpp └── websockets.pro /.cmake.conf: -------------------------------------------------------------------------------- 1 | set(QT_REPO_MODULE_VERSION "6.10.0") 2 | set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "alpha1") 3 | set(QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_AS_CONST=1") 4 | list(APPEND QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_FOREACH=1") 5 | list(APPEND QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_USE_NODISCARD_FILE_OPEN=1") 6 | -------------------------------------------------------------------------------- /.gitreview: -------------------------------------------------------------------------------- 1 | [gerrit] 2 | host=codereview.qt-project.org 3 | project=qt/qtwebsockets 4 | defaultbranch=dev 5 | -------------------------------------------------------------------------------- /.tag: -------------------------------------------------------------------------------- 1 | 638b7cd687d5077c79bb619840cfc9ea9f92c7ce 2 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from qtwebsockets.pro. 5 | 6 | cmake_minimum_required(VERSION 3.16) 7 | 8 | include(.cmake.conf) 9 | project(QtWebSockets # special case 10 | VERSION "${QT_REPO_MODULE_VERSION}" 11 | DESCRIPTION "Qt WebSockets Libraries" # special case 12 | HOMEPAGE_URL "https://qt.io/" 13 | LANGUAGES CXX C 14 | ) 15 | 16 | # Make sure we use the fixed BASE argument of qt_add_resource. 17 | set(QT_USE_FIXED_QT_ADD_RESOURCE_BASE TRUE) 18 | 19 | find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals Core Network) # special case 20 | find_package(Qt6 ${PROJECT_VERSION} CONFIG OPTIONAL_COMPONENTS Quick QuickTest) # special case 21 | qt_internal_project_setup() 22 | 23 | if(NOT TARGET Qt::Network) 24 | message(NOTICE "Skipping the build as the condition \"TARGET Qt::Network\" is not met.") 25 | return() 26 | endif() 27 | qt_build_repo() 28 | -------------------------------------------------------------------------------- /LICENSES/BSD-3-Clause.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) . 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 7 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 8 | 9 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 10 | -------------------------------------------------------------------------------- /LICENSES/LicenseRef-Qt-Commercial.txt: -------------------------------------------------------------------------------- 1 | Licensees holding valid commercial Qt licenses may use this software in 2 | accordance with the the terms contained in a written agreement between 3 | you and The Qt Company. Alternatively, the terms and conditions that were 4 | accepted by the licensee when buying and/or downloading the 5 | software do apply. 6 | 7 | For the latest licensing terms and conditions, see https://www.qt.io/terms-conditions. 8 | For further information use the contact form at https://www.qt.io/contact-us. 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Qt WebSockets 2 | 3 | ### Package Brief 4 | 5 | `QtWebSockets` is a pure Qt implementation of WebSockets - both client and server. 6 | It is implemented as a Qt add-on module that can easily be embedded into existing Qt projects. 7 | Its only dependency is Qt. 8 | 9 | ### Documentation 10 | 11 | The documentation can be found in the following places: 12 | * The online Qt documentation: 13 | * [Qt WebSockets documentation](https://doc.qt.io/qt-6/qtwebsockets-index.html) 14 | * Build from source: 15 | * [Building Qt Documentation](https://wiki.qt.io/Building_Qt_Documentation) 16 | 17 | *Note that the documentation links in this document will always be for the 18 | latest Qt 6 version. If you need to browse the documentation for a specific 19 | version, you can [browse the archives](https://doc.qt.io/archives/).* 20 | 21 | ### Features 22 | 23 | * Client and server capable 24 | * Text and binary sockets 25 | * Frame-based and message-based signals 26 | * Strict Unicode checking 27 | * WSS and proxy support 28 | 29 | ### Compliance 30 | 31 | `QtWebSockets` is compliant with [RFC6455](http://datatracker.ietf.org/doc/rfc6455/?include_text=1) and has been tested with the [Autobahn Testsuite](http://autobahn.ws/testsuite). 32 | 33 | ### Missing Features 34 | 35 | * Extensions 36 | 37 | ### Build Process 38 | 39 | Building the package/repository does depend on the Qt packages listed in dependencies.yaml. 40 | Further dependencies to system packages are listed in the configure output. 41 | 42 | See the [documentation](https://doc.qt.io/qt-6/build-sources.html) for general 43 | advice on building the Qt framework and its modules from sources. Further 44 | information on how to build from source is also available in the 45 | [wiki](https://wiki.qt.io/Building_Qt_6_from_Git). 46 | 47 | ### Report an Issue 48 | 49 | If you spot a bug, follow [these](https://doc.qt.io/qt-6/bughowto.html) 50 | steps to report it. 51 | 52 | ### Contribute to Qt 53 | 54 | We welcome contributions to Qt! If you'd like to contribute, read the 55 | [Qt Contribution Guidelines](https://wiki.qt.io/Qt_Contribution_Guidelines). 56 | 57 | ### Licensing 58 | 59 | Qt is available under various licenses. For details, check out the 60 | [license documentation](https://doc.qt.io/qt-6/licensing.html). 61 | -------------------------------------------------------------------------------- /REUSE.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[annotations]] 4 | path = ["src/imports/qmlwebsockets/plugins.qmltypes"] 5 | precedence = "closest" 6 | comment = "source and plugins" 7 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 8 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only" 9 | 10 | [[annotations]] 11 | path = ["tests/**.txt", "tests/**.cert", "tests/**.key"] 12 | precedence = "closest" 13 | comment = "test" 14 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 15 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GPL-3.0-only" 16 | 17 | [[annotations]] 18 | path = ["**.pro", ".cmake.conf", "**.yaml", "**.json", "**.cfg", "**BLACKLIST", ".tag"] 19 | precedence = "closest" 20 | comment = "build system" 21 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 22 | SPDX-License-Identifier = "BSD-3-Clause" 23 | 24 | [[annotations]] 25 | path = ["**/.gitattributes", "**.gitignore", "**.gitreview"] 26 | precedence = "closest" 27 | comment = "version control system. Infrastructure" 28 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 29 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR BSD-3-Clause" 30 | 31 | [[annotations]] 32 | path = ["examples/**"] 33 | comment = "this must be after the build system table because example and snippets take precedence over build system" 34 | precedence = "closest" 35 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 36 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR BSD-3-Clause" 37 | 38 | [[annotations]] 39 | path = ["**/doc/images/**", "**/README*", "**.qdocconf"] 40 | comment = "documentation" 41 | precedence = "closest" 42 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 43 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only" 44 | 45 | [[annotations]] 46 | path = ["**.toml", "licenseRule.json"] 47 | precedence = "override" 48 | comment = "infrastructure" 49 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 50 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR BSD-3-Clause" 51 | 52 | [[annotations]] 53 | path = ["**/qt_attribution.json"] 54 | precedence = "override" 55 | comment = "documentation" 56 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 57 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only" 58 | -------------------------------------------------------------------------------- /coin/axivion/ci_config_linux.json: -------------------------------------------------------------------------------- 1 | { 2 | "Project": { 3 | "BuildSystemIntegration": { 4 | "child_order": [ 5 | "GCCSetup", 6 | "CMake", 7 | "LinkLibraries" 8 | ] 9 | }, 10 | "CMake": { 11 | "_active": true, 12 | "_copy_from": "CMakeIntegration", 13 | "build_environment": {}, 14 | "build_options": "-j4", 15 | "generate_options": "--fresh", 16 | "generator": "Ninja" 17 | }, 18 | "GCCSetup": { 19 | "_active": true, 20 | "_copy_from": "Command", 21 | "build_command": "gccsetup --cc gcc --cxx g++ --config ../../../axivion/" 22 | }, 23 | "LinkLibraries": { 24 | "_active": true, 25 | "_copy_from": "AxivionLinker", 26 | "input_files": [ 27 | "build/lib/lib*.so*.ir", 28 | "build/qml/*/lib*.so*.ir" 29 | ], 30 | "ir": "build/$(env:TESTED_MODULE_COIN).ir" 31 | } 32 | }, 33 | "_Format": "1.0", 34 | "_Version": "7.6.2", 35 | "_VersionNum": [ 36 | 7, 37 | 6, 38 | 2, 39 | 12725 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /coin/module_config.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | accept_configuration: 3 | condition: property 4 | property: features 5 | not_contains_value: Disable 6 | 7 | instructions: 8 | Build: 9 | - type: EnvironmentVariable 10 | variableName: VERIFY_SOURCE_SBOM 11 | variableValue: "ON" 12 | - !include "{{qt/qtbase}}/coin_module_build_template_v2.yaml" 13 | 14 | Test: 15 | - !include "{{qt/qtbase}}/coin_module_test_template_v3.yaml" 16 | - !include "{{qt/qtbase}}/coin_module_test_docs.yaml" 17 | -------------------------------------------------------------------------------- /dependencies.yaml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | ../qtbase: 3 | ref: a867a16ef0a29f9b8b7196d0959e980ee17d7876 4 | required: true 5 | ../qtdeclarative: 6 | ref: fa4568622cc19e5a876238d6cfca2e95936f8bdd 7 | required: false 8 | -------------------------------------------------------------------------------- /dist/REUSE.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[annotations]] 4 | path = ["*"] 5 | precedence = "override" 6 | comment = "Licensed as documentation." 7 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 8 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only" 9 | -------------------------------------------------------------------------------- /dist/changes-5.10.0: -------------------------------------------------------------------------------- 1 | Qt 5.10 introduces many new features and improvements as well as bugfixes 2 | over the 5.9.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.10 series is binary compatible with the 5.9.x series. 8 | Applications compiled for 5.9 will continue to run with 5.10. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * Qt 5.10.0 Changes * 20 | **************************************************************************** 21 | 22 | - This release contains only minor code improvements. 23 | -------------------------------------------------------------------------------- /dist/changes-5.10.1: -------------------------------------------------------------------------------- 1 | Qt 5.10.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.10.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.10 series is binary compatible with the 5.9.x series. 10 | Applications compiled for 5.9 will continue to run with 5.10. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | This release contains all fixes included in the Qt 5.9.4 release. 21 | 22 | **************************************************************************** 23 | * Qt 5.10.1 Changes * 24 | **************************************************************************** 25 | 26 | - This release does not contain any changes to this module. 27 | -------------------------------------------------------------------------------- /dist/changes-5.11.0: -------------------------------------------------------------------------------- 1 | Qt 5.11 introduces many new features and improvements as well as bugfixes 2 | over the 5.10.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 8 | Applications compiled for 5.10 will continue to run with 5.11. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * Qt 5.11.0 Changes * 20 | **************************************************************************** 21 | 22 | - This release contains only minor code improvements. 23 | -------------------------------------------------------------------------------- /dist/changes-5.11.1: -------------------------------------------------------------------------------- 1 | Qt 5.11.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.11.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 10 | Applications compiled for 5.10 will continue to run with 5.11. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.11.1 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.11.2: -------------------------------------------------------------------------------- 1 | Qt 5.11.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.11.0 through 5.11.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 10 | Applications compiled for 5.10 will continue to run with 5.11. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.11.2 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.11.3: -------------------------------------------------------------------------------- 1 | Qt 5.11.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.11.0 through 5.11.2. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 10 | Applications compiled for 5.10 will continue to run with 5.11. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.12.0: -------------------------------------------------------------------------------- 1 | Qt 5.12 introduces many new features and improvements as well as bugfixes 2 | over the 5.11.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 8 | Applications compiled for 5.11 will continue to run with 5.12. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * QWebSocket * 20 | **************************************************************************** 21 | 22 | - Added the bytesToWrite function to QWebSocket. Call this function to see 23 | how many bytes are left to write. 24 | 25 | **************************************************************************** 26 | * QWebSocketServer * 27 | **************************************************************************** 28 | 29 | - Introduced nativeDescriptor and setNativeDescriptor. These functions are 30 | replacing socketDescriptor and setSocketDescriptor which are now 31 | deprecated. 32 | 33 | **************************************************************************** 34 | * Platform Specific Changes * 35 | **************************************************************************** 36 | 37 | Wasm 38 | ----- 39 | - [QTBUG-70339] Add support for WebSockets on Qt for WASM 40 | -------------------------------------------------------------------------------- /dist/changes-5.12.1: -------------------------------------------------------------------------------- 1 | Qt 5.12.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.12.2: -------------------------------------------------------------------------------- 1 | Qt 5.12.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.12.3: -------------------------------------------------------------------------------- 1 | Qt 5.12.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.2. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.12.4: -------------------------------------------------------------------------------- 1 | Qt 5.12.4 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.3. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.12.5: -------------------------------------------------------------------------------- 1 | Qt 5.12.5 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.4. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.13.0: -------------------------------------------------------------------------------- 1 | Qt 5.13 introduces many new features and improvements as well as bugfixes 2 | over the 5.12.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.13 series is binary compatible with the 5.12.x series. 8 | Applications compiled for 5.12 will continue to run with 5.13. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | - This release contains only minor code improvements. 19 | -------------------------------------------------------------------------------- /dist/changes-5.13.1: -------------------------------------------------------------------------------- 1 | Qt 5.13.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.13.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.13 series is binary compatible with the 5.12.x series. 10 | Applications compiled for 5.12 will continue to run with 5.13. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.13.2: -------------------------------------------------------------------------------- 1 | Qt 5.13.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.13.0 through 5.13.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.13 series is binary compatible with the 5.12.x series. 10 | Applications compiled for 5.12 will continue to run with 5.13. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.14.0: -------------------------------------------------------------------------------- 1 | Qt 5.14 introduces many new features and improvements as well as bugfixes 2 | over the 5.13.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.14 series is binary compatible with the 5.13.x series. 8 | Applications compiled for 5.13 will continue to run with 5.14. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * QWebSocket * 20 | **************************************************************************** 21 | 22 | - [QTBUG-74464] QWebSocket no longer marks the connection as timed out 23 | if it cannot read a whole message within 5 seconds. It will also no 24 | longer block for up to 5 seconds when receiving a message. 25 | 26 | **************************************************************************** 27 | * QWebSocketServer * 28 | **************************************************************************** 29 | 30 | - [QTBUG-57026] [QTBUG-63312] Handshake timeout 31 | * Added a timeout to the websocket handshake, 10 seconds by default. 32 | * Call setHandshakeTimeout() to change the maximum duration. 33 | Negative values mean it will not time out. 34 | * handshakeTimeout() and handshakeTimeoutMS() can be used to query the 35 | current timeout duration. 36 | -------------------------------------------------------------------------------- /dist/changes-5.14.1: -------------------------------------------------------------------------------- 1 | Qt 5.14.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.14.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.14 series is binary compatible with the 5.13.x series. 10 | Applications compiled for 5.13 will continue to run with 5.14. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.14.2: -------------------------------------------------------------------------------- 1 | Qt 5.14.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.14.0 through 5.14.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.14 series is binary compatible with the 5.13.x series. 10 | Applications compiled for 5.13 will continue to run with 5.14. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.15.0: -------------------------------------------------------------------------------- 1 | Qt 5.15 introduces many new features and improvements as well as bugfixes 2 | over the 5.14.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.15 series is binary compatible with the 5.14.x series. 8 | Applications compiled for 5.14 will continue to run with 5.15. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * QWebSocket * 20 | **************************************************************************** 21 | 22 | - [QTBUG-70693] Added public API to set the maximum frame size and 23 | message size 24 | -------------------------------------------------------------------------------- /dist/changes-5.15.1: -------------------------------------------------------------------------------- 1 | Qt 5.15.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.15.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.15 series is binary compatible with the 5.14.x series. 10 | Applications compiled for 5.14 will continue to run with 5.15. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.15.2: -------------------------------------------------------------------------------- 1 | Qt 5.15.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.15.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5.15/index.html 8 | 9 | The Qt version 5.15 series is binary compatible with the 5.14.x series. 10 | Applications compiled for 5.14 will continue to run with 5.15. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Important Behavior Changes * 22 | **************************************************************************** 23 | 24 | **************************************************************************** 25 | * Library * 26 | **************************************************************************** 27 | 28 | 29 | -------------------------------------------------------------------------------- /dist/changes-5.5.0: -------------------------------------------------------------------------------- 1 | Qt 5.5 introduces many new features and improvements as well as bugfixes 2 | over the 5.4.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.5 series is binary compatible with the 5.4.x series. 8 | Applications compiled for 5.4 will continue to run with 5.5. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * QML * 20 | **************************************************************************** 21 | 22 | - The import statement has changed from "import Qt.WebSockets 1.0" to 23 | "import QtWebSockets 1.0". The old statement is still supported, but it 24 | cannot be mixed with the new statement within the same project. 25 | 26 | **************************************************************************** 27 | * QtWebSockets * 28 | **************************************************************************** 29 | 30 | - QWebSocket: 31 | * [QTBUG-41285] Fixed QWebSocket's handling of query parameters with 32 | encoded characters 33 | * [QTBUG-42298] Added masking of ping from client side based on RFC 6455, 34 | Section 5.1. 35 | * [QTBUG-44893] Fixed spurious error signals on first connection 36 | * [QTBUG-44889] Fixed handling of url paths with encoded characters 37 | * [QTBUG-46055] Corrected the default port of secure hand shake request 38 | 39 | - QWebSocketServer: 40 | * [QTBUG-44866] Avoid hanging after an invalid SSL request 41 | * [QTBUG-45331] Fixed a crash when destroying the QWebSocketServer 42 | 43 | **************************************************************************** 44 | * Platform Specific Changes * 45 | **************************************************************************** 46 | 47 | WinRT 48 | ----- 49 | - [QTBUG-44491] Fixed the build for WinRT/ARM 50 | -------------------------------------------------------------------------------- /dist/changes-5.6.3: -------------------------------------------------------------------------------- 1 | Qt 5.6.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.6.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.6 series is binary compatible with the 5.5.x series. 10 | Applications compiled for 5.5 will continue to run with 5.6. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Library * 22 | **************************************************************************** 23 | - QWebSocketHandshakeRequest 24 | [QTBUG-57357] Fixed the parsing of port in handshake requests. 25 | -------------------------------------------------------------------------------- /dist/changes-5.7.0: -------------------------------------------------------------------------------- 1 | Qt 5.7 introduces many new features and improvements as well as bugfixes 2 | over the 5.6.x series. Also, there is a change in the licensing terms. 3 | For more details, refer to the online documentation included in this 4 | distribution. The documentation is also available online: 5 | 6 | http://doc.qt.io/qt-5.7 7 | 8 | The Qt version 5.7 series is binary compatible with the 5.6.x series. 9 | Applications compiled for 5.6 will continue to run with 5.7. 10 | 11 | Some of the changes listed in this file include issue tracking numbers 12 | corresponding to tasks in the Qt Bug Tracker: 13 | 14 | http://bugreports.qt.io/ 15 | 16 | Each of these identifiers can be entered in the bug tracker to obtain more 17 | information about a particular change. 18 | 19 | **************************************************************************** 20 | * Important License Changes * 21 | **************************************************************************** 22 | 23 | This module is no longer available under LGPLv2.1. The libraries are 24 | now available under the following licenses: 25 | * Commercial License 26 | * GNU General Public License v2.0 (LICENSE.GPL2) and later 27 | * GNU Lesser General Public License v3.0 (LICENSE.LGPL3) 28 | 29 | The tools are now available under the following licenses: 30 | * Commercial License 31 | * GNU General Public License 3.0 (LICENSE.GPL3) with exceptions 32 | described in The Qt Company GPL Exception 1.0 (LICENSE.GPL3-EXCEPT) 33 | 34 | **************************************************************************** 35 | * General * 36 | **************************************************************************** 37 | - This release contains only minor improvements. 38 | -------------------------------------------------------------------------------- /dist/changes-5.8.0: -------------------------------------------------------------------------------- 1 | Qt 5.8 introduces many new features and improvements as well as bugfixes 2 | over the 5.7.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.8 series is binary compatible with the 5.7.x series. 8 | Applications compiled for 5.7 will continue to run with 5.8. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | QWebSocket 19 | ---------- 20 | 21 | - It is now possible to use TLS PSK ciphersuites. 22 | -------------------------------------------------------------------------------- /dist/changes-5.9.0: -------------------------------------------------------------------------------- 1 | Qt 5.9 introduces many new features and improvements as well as bugfixes 2 | over the 5.8.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 8 | Applications compiled for 5.8 will continue to run with 5.9. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * Library * 20 | **************************************************************************** 21 | 22 | - QWebSocketServer 23 | * [QTBUG-56129] SslMode::NonSecure enumerator now always has the same 24 | value (1) regardless of SSL being enabled or disabled. 25 | * [QTBUG-54276] Added a member function to handle external QTcpSocket, 26 | upgrading it to a QWebSocket. 27 | * [QTBUG-56414] Server now deletes a websocket when a 'disconnected' 28 | signal is received. 29 | - QWebSocketHandshakeRequest 30 | [QTBUG-57357] Fixed the parsing of port in handshake requests. 31 | - QWebSocketDataProcessor 32 | [QTBUG-55506] Call clear() before emitting textMessageReceived or 33 | binaryMessageReceived to avoid data corruption in case a slot blocks 34 | (for example, entering a nested modal loop while showing this message) 35 | while socket receives more data. 36 | - QQmlWebSocket 37 | * [QTBUG-58278] Fix setUrl: only call open() if the 'active' property is 38 | true. 39 | 40 | -------------------------------------------------------------------------------- /dist/changes-5.9.1: -------------------------------------------------------------------------------- 1 | Qt 5.9.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Library * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.9.2: -------------------------------------------------------------------------------- 1 | Qt 5.9.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | -------------------------------------------------------------------------------- /dist/changes-5.9.3: -------------------------------------------------------------------------------- 1 | Qt 5.9.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.3 Changes * 22 | **************************************************************************** 23 | 24 | - Fixed a race condition in QWebSocketServer where the server would, 25 | in rare cases, miss the start of the handshake coming from a client. 26 | - Other minor code improvements. 27 | -------------------------------------------------------------------------------- /dist/changes-5.9.4: -------------------------------------------------------------------------------- 1 | Qt 5.9.4 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.4 Changes * 22 | **************************************************************************** 23 | 24 | - This release does not contain any changes to this module. 25 | 26 | -------------------------------------------------------------------------------- /dist/changes-5.9.5: -------------------------------------------------------------------------------- 1 | Qt 5.9.5 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.5 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.9.6: -------------------------------------------------------------------------------- 1 | Qt 5.9.6 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0 through 5.9.5. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.6 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | qt_examples_build_begin(EXTERNAL_BUILD) 5 | 6 | add_subdirectory(websockets) 7 | 8 | qt_examples_build_end() 9 | -------------------------------------------------------------------------------- /examples/examples.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | SUBDIRS = websockets 4 | -------------------------------------------------------------------------------- /examples/websockets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | if(TARGET Qt::Quick) 5 | qt_internal_add_example(qmlwebsocketclient) 6 | qt_internal_add_example(qmlwebsocketserver) 7 | endif() 8 | if (NOT ANDROID) 9 | qt_internal_add_example(echoclient) 10 | qt_internal_add_example(echoserver) 11 | qt_internal_add_example(simplechat) 12 | if(QT_FEATURE_ssl) 13 | qt_internal_add_example(sslechoserver) 14 | qt_internal_add_example(sslechoclient) 15 | endif() 16 | endif() 17 | -------------------------------------------------------------------------------- /examples/websockets/doc/echoclient.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example echoclient 6 | \title WebSocket Echo Client 7 | \examplecategory {Networking} 8 | \ingroup qtwebsockets-examples 9 | \brief Show how to write a simple WebSocket client application. 10 | 11 | The Echo Client shows how to use the \l {Qt WebSockets}{WebSocket} 12 | API to send a message to a server and process whatever response the 13 | server returns - in this case, simply reporting the response. 14 | 15 | The client by default opens a WebSocket connection to a server listening 16 | on local port 1234. When the connection attempt is successful, the client 17 | will send a message to the server and print out whatever response the 18 | server sends. The client then closes the connection. 19 | 20 | \image echoclient-console-example.webp WebSocket Echo Console Client 21 | 22 | For the sake of illustration, we use the \l {WebSocket Echo Server}, whose 23 | reply is simply the message that was sent. 24 | 25 | \sa {WebSocket Echo Server} 26 | */ 27 | -------------------------------------------------------------------------------- /examples/websockets/doc/echoserver.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example echoserver 6 | \title WebSocket Echo Server 7 | \examplecategory {Networking} 8 | \ingroup qtwebsockets-examples 9 | \brief Show how to write a simple WebSocket server application. 10 | 11 | This Echo Server shows how to create a simple server application that sends 12 | back a reply in response to a message it receives, using the 13 | \l {Qt WebSockets}{WebSocket} API. For the sake of illustration, the reply 14 | is simply a copy of the message. 15 | 16 | If your web browser supports \l {Qt WebSockets}{WebSocket}, you can also use it 17 | to open the \c {echoserver/echoclient.html}{echoclient.html} file, and operate 18 | as shown in the following screenshot: 19 | 20 | \image echoclient-html-example.png WebSocket Echo HTML Client 21 | 22 | Otherwise use the \l {WebSocket Echo Client} to connect to the server. 23 | 24 | \sa {WebSocket Echo Client} 25 | */ 26 | -------------------------------------------------------------------------------- /examples/websockets/doc/examples.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | 5 | /*! 6 | \group qtwebsockets-examples 7 | \title Qt WebSockets Examples 8 | \brief List of Qt WebSocket examples 9 | 10 | The examples below can be used as a guide to using the \l{Qt WebSockets} API. 11 | */ 12 | -------------------------------------------------------------------------------- /examples/websockets/doc/images/echoclient-console-example.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/638b7cd687d5077c79bb619840cfc9ea9f92c7ce/examples/websockets/doc/images/echoclient-console-example.webp -------------------------------------------------------------------------------- /examples/websockets/doc/images/echoclient-html-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/638b7cd687d5077c79bb619840cfc9ea9f92c7ce/examples/websockets/doc/images/echoclient-html-example.png -------------------------------------------------------------------------------- /examples/websockets/doc/images/qmlwebsocketclient-example.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/638b7cd687d5077c79bb619840cfc9ea9f92c7ce/examples/websockets/doc/images/qmlwebsocketclient-example.webp -------------------------------------------------------------------------------- /examples/websockets/doc/images/qmlwebsocketserver-example.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/638b7cd687d5077c79bb619840cfc9ea9f92c7ce/examples/websockets/doc/images/qmlwebsocketserver-example.webp -------------------------------------------------------------------------------- /examples/websockets/doc/images/simplechat-html-example.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/638b7cd687d5077c79bb619840cfc9ea9f92c7ce/examples/websockets/doc/images/simplechat-html-example.webp -------------------------------------------------------------------------------- /examples/websockets/doc/images/sslechoclient-console-example.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/638b7cd687d5077c79bb619840cfc9ea9f92c7ce/examples/websockets/doc/images/sslechoclient-console-example.webp -------------------------------------------------------------------------------- /examples/websockets/doc/images/sslechoclient-html-example.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/638b7cd687d5077c79bb619840cfc9ea9f92c7ce/examples/websockets/doc/images/sslechoclient-html-example.webp -------------------------------------------------------------------------------- /examples/websockets/doc/qmlwebsocketclient.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example qmlwebsocketclient 6 | \title QML WebSocket Client 7 | \examplecategory {Networking} 8 | \ingroup qtwebsockets-examples 9 | \brief Explains how to write a QML WebSocket client example. 10 | 11 | The QML WebSocket Client example creates a secure and an 12 | insecure \l {Qt WebSockets}{WebSocket} connection to an echo 13 | server, using the QML API, and alternates between opening 14 | connections and closing them. Every time a connection has 15 | been opened, it sends a message. 16 | 17 | \image qmlwebsocketclient-example.webp QML WebSocket Client GUI 18 | 19 | This example opens a window with a welcome message. Every time 20 | the window is clicked on, it alternates between opening and 21 | closing two connections to an external echo server. The echo 22 | server used is at ws.ifelse.io, and an Internet connection is 23 | necessary for the example to work. Also TLS must be enabled for 24 | the secure connection to work. When the connection is opened or 25 | closed, the statusChanged signal is handled by the 26 | onStatusChanged handler. Every time the socket is opened, a 27 | message is sent, and every time the socket is closed, a message 28 | is logged in the window. In addition, there is an 29 | onTextMessageReceived handler that logs to the window the 30 | messages received from the server. 31 | */ 32 | -------------------------------------------------------------------------------- /examples/websockets/doc/qmlwebsocketserver.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example qmlwebsocketserver 6 | \title QML WebSocket Server 7 | \examplecategory {Networking} 8 | \ingroup qtwebsockets-examples 9 | \brief A simple example that shows how to use a QML WebSocketServer. 10 | 11 | \image qmlwebsocketserver-example.webp QML WebSocket Server GUI 12 | 13 | This example opens a window and has a WebSocketServer listening 14 | for incoming connections and a WebSocket connecting to the 15 | WebSocketServer. Every time the window is clicked, the WebSocket 16 | sends a message to the WebSocketServer. The WebSocketServer has a 17 | signal handler that logs the incoming message to the window and 18 | sends a message back again, and the WebSocket has a signal 19 | handler that logs the returned message to the window. 20 | */ 21 | -------------------------------------------------------------------------------- /examples/websockets/doc/simplechat.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example simplechat 6 | \title Simple WebSocket Chat 7 | \examplecategory {Networking} 8 | \ingroup qtwebsockets-examples 9 | \brief A minimal chat application using the WebSocket protocol. 10 | 11 | This application shows how to use the QWebSocket and QWebSocketServer 12 | classes to create a minimalist chat application over the WebSocket protocol. 13 | The example is a server that allows multiple clients to connect to it to send 14 | and receive messages. 15 | 16 | By default it listens at localhost port 1234. It keeps track of all clients 17 | that are connected to it, and each time one of the clients sends a message to 18 | the server, the message is forwarded to all other clients. When a client 19 | disconnects, it is removed from the list of clients. 20 | 21 | \image simplechat-html-example.webp Simple WebSocket Chat HTML Client 22 | 23 | There is also an HTML-client that is used to connect to and disconnect from 24 | the server, query about the connection, send messages, and view all the 25 | messages sent by other clients. 26 | 27 | */ 28 | -------------------------------------------------------------------------------- /examples/websockets/doc/sslechoclient.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example sslechoclient 6 | \title Secure WebSocket Echo Client 7 | \examplecategory {Networking} 8 | \ingroup qtwebsockets-examples 9 | \brief A simple client application using secure WebSockets (wss). 10 | 11 | The Secure WebSocket Echo Client example shows how to use the 12 | \l {Qt WebSockets}{WebSocket} class to implement an echo client over 13 | a secure connection (wss). It connects to a server and sends a message, 14 | and when it receives a message back, it prints it out and exits. SSL 15 | support is required for this example to work. 16 | 17 | This example connects by default to localhost at port 1234 using a secure 18 | connection. It trusts the certificates signed by the CA certificates 19 | configured in the SSL backend, and in addition trusts the certificate 20 | used by \l {Secure WebSocket Echo Server}. 21 | 22 | \image echoclient-console-example.webp Secure WebSocket Echo Console Client 23 | 24 | \sa {WebSocket Echo Client}, {Secure WebSocket Echo Server} 25 | */ 26 | -------------------------------------------------------------------------------- /examples/websockets/doc/sslechoserver.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example sslechoserver 6 | \title Secure WebSocket Echo Server 7 | \examplecategory {Networking} 8 | \ingroup qtwebsockets-examples 9 | \brief A simple server to respond to clients over secure WebSockets (wss). 10 | 11 | The Secure WebSocket Echo Server example shows how to use the QWebSocketServer 12 | class to implement a simple echo server over secure sockets (wss). TLS support 13 | is required for this example to work. It authenticates itself to the client 14 | and, on success, can accept a message from the client, to which it responds. 15 | For the sake of illustration, its response is simply a copy of the message 16 | it was sent. 17 | 18 | This server is configured with a self-signed certificate and key. 19 | Unless the clients contacting this server is configured to trust that 20 | certificate, which \l {Secure WebSocket Echo Client} does, they will reject 21 | this server. 22 | 23 | \image sslechoclient-html-example.webp Secure WebSocket Echo HTML Client 24 | 25 | There is an HTML-based client as part of this example. But it will only 26 | work either if the browser used supports the certificate as described above, 27 | or if it ignores TLS errors for localhost addresses. 28 | 29 | \sa {Secure WebSocket Echo Client}, {WebSocket Echo Server} 30 | */ 31 | -------------------------------------------------------------------------------- /examples/websockets/echoclient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(echoclient LANGUAGES CXX) 6 | 7 | if (ANDROID) 8 | message(FATAL_ERROR "This project cannot be built on Android.") 9 | endif() 10 | 11 | set(CMAKE_AUTOMOC ON) 12 | 13 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 14 | set(INSTALL_EXAMPLESDIR "examples") 15 | endif() 16 | 17 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/echoclient") 18 | 19 | find_package(Qt6 REQUIRED COMPONENTS Core WebSockets) 20 | 21 | qt_add_executable(echoclient 22 | echoclient.cpp echoclient.h 23 | main.cpp 24 | ) 25 | 26 | set_target_properties(echoclient PROPERTIES 27 | WIN32_EXECUTABLE FALSE 28 | MACOSX_BUNDLE FALSE 29 | ) 30 | 31 | target_link_libraries(echoclient PUBLIC 32 | Qt::Core 33 | Qt::WebSockets 34 | ) 35 | 36 | install(TARGETS echoclient 37 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 38 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 39 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 40 | ) 41 | -------------------------------------------------------------------------------- /examples/websockets/echoclient/echoclient.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include "echoclient.h" 4 | #include 5 | 6 | QT_USE_NAMESPACE 7 | 8 | //! [constructor] 9 | EchoClient::EchoClient(const QUrl &url, bool debug, QObject *parent) : 10 | QObject(parent), 11 | m_debug(debug) 12 | { 13 | if (m_debug) 14 | qDebug() << "WebSocket server:" << url; 15 | connect(&m_webSocket, &QWebSocket::connected, this, &EchoClient::onConnected); 16 | connect(&m_webSocket, &QWebSocket::disconnected, this, &EchoClient::closed); 17 | m_webSocket.open(url); 18 | } 19 | //! [constructor] 20 | 21 | //! [onConnected] 22 | void EchoClient::onConnected() 23 | { 24 | if (m_debug) 25 | qDebug() << "WebSocket connected"; 26 | connect(&m_webSocket, &QWebSocket::textMessageReceived, 27 | this, &EchoClient::onTextMessageReceived); 28 | m_webSocket.sendTextMessage(QStringLiteral("Hello, world!")); 29 | } 30 | //! [onConnected] 31 | 32 | //! [onTextMessageReceived] 33 | void EchoClient::onTextMessageReceived(QString message) 34 | { 35 | if (m_debug) 36 | qDebug() << "Message received:" << message; 37 | m_webSocket.close(); 38 | } 39 | //! [onTextMessageReceived] 40 | -------------------------------------------------------------------------------- /examples/websockets/echoclient/echoclient.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #ifndef ECHOCLIENT_H 4 | #define ECHOCLIENT_H 5 | 6 | #include 7 | #include 8 | 9 | class EchoClient : public QObject 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit EchoClient(const QUrl &url, bool debug = false, QObject *parent = nullptr); 14 | 15 | Q_SIGNALS: 16 | void closed(); 17 | 18 | private Q_SLOTS: 19 | void onConnected(); 20 | void onTextMessageReceived(QString message); 21 | 22 | private: 23 | QWebSocket m_webSocket; 24 | bool m_debug; 25 | }; 26 | 27 | #endif // ECHOCLIENT_H 28 | -------------------------------------------------------------------------------- /examples/websockets/echoclient/echoclient.pro: -------------------------------------------------------------------------------- 1 | QT += core websockets 2 | QT -= gui 3 | 4 | TARGET = echoclient 5 | CONFIG += console 6 | CONFIG -= app_bundle 7 | 8 | TEMPLATE = app 9 | 10 | SOURCES += \ 11 | main.cpp \ 12 | echoclient.cpp 13 | 14 | HEADERS += \ 15 | echoclient.h 16 | 17 | target.path = $$[QT_INSTALL_EXAMPLES]/websockets/echoclient 18 | INSTALLS += target 19 | -------------------------------------------------------------------------------- /examples/websockets/echoclient/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include 4 | #include 5 | #include 6 | #include "echoclient.h" 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | using namespace Qt::Literals::StringLiterals; 11 | QCoreApplication a(argc, argv); 12 | 13 | QCommandLineParser parser; 14 | parser.setApplicationDescription("QtWebSockets example: echoclient"); 15 | parser.addHelpOption(); 16 | 17 | QCommandLineOption dbgOption( 18 | QStringList{ u"d"_s, u"debug"_s }, 19 | QCoreApplication::translate("main", "Debug output [default: off].")); 20 | parser.addOption(dbgOption); 21 | QCommandLineOption hostnameOption( 22 | QStringList{ u"n"_s, u"hostname"_s }, 23 | QCoreApplication::translate("main", "Hostname [default: localhost]."), "hostname", 24 | "localhost"); 25 | parser.addOption(hostnameOption); 26 | QCommandLineOption portOption(QStringList{ u"p"_s, u"port"_s }, 27 | QCoreApplication::translate("main", "Port [default: 1234]."), 28 | "port", "1234"); 29 | parser.addOption(portOption); 30 | 31 | parser.process(a); 32 | bool debug = parser.isSet(dbgOption); 33 | bool ok = true; 34 | int port = parser.value(portOption).toInt(&ok); 35 | if (!ok || port < 1 || port > 65535) { 36 | qWarning("Port invalid, must be a number between 1 and 65535\n%s", 37 | qPrintable(parser.helpText())); 38 | return 1; 39 | } 40 | QUrl url; 41 | url.setScheme(u"ws"_s); 42 | url.setHost(parser.value(hostnameOption)); 43 | url.setPort(port); 44 | EchoClient client(url, debug); 45 | QObject::connect(&client, &EchoClient::closed, &a, &QCoreApplication::quit); 46 | 47 | return a.exec(); 48 | } 49 | -------------------------------------------------------------------------------- /examples/websockets/echoserver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(echoserver LANGUAGES CXX) 6 | 7 | if (ANDROID) 8 | message(FATAL_ERROR "This project cannot be built on Android.") 9 | endif() 10 | 11 | set(CMAKE_AUTOMOC ON) 12 | 13 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 14 | set(INSTALL_EXAMPLESDIR "examples") 15 | endif() 16 | 17 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/echoserver") 18 | 19 | find_package(Qt6 REQUIRED COMPONENTS WebSockets) 20 | 21 | qt_add_executable(echoserver 22 | echoserver.cpp echoserver.h 23 | main.cpp 24 | ) 25 | 26 | set_target_properties(echoserver PROPERTIES 27 | WIN32_EXECUTABLE FALSE 28 | MACOSX_BUNDLE FALSE 29 | ) 30 | 31 | target_link_libraries(echoserver PUBLIC 32 | Qt::WebSockets 33 | ) 34 | 35 | install(TARGETS echoserver 36 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 37 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 38 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 39 | ) 40 | -------------------------------------------------------------------------------- /examples/websockets/echoserver/echoclient.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | WebSocket Echo Client 4 | 5 | 6 |

WebSocket Echo Client

7 |

8 | 9 | 10 | 11 |

12 |

13 | 14 |

15 |

16 | 17 | 18 |

19 | 20 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /examples/websockets/echoserver/echoserver.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include "echoserver.h" 4 | #include "QtWebSockets/qwebsocketserver.h" 5 | #include "QtWebSockets/qwebsocket.h" 6 | #include 7 | 8 | QT_USE_NAMESPACE 9 | 10 | //! [constructor] 11 | EchoServer::EchoServer(quint16 port, bool debug, QObject *parent) : 12 | QObject(parent), 13 | m_pWebSocketServer(new QWebSocketServer(QStringLiteral("Echo Server"), 14 | QWebSocketServer::NonSecureMode, this)), 15 | m_debug(debug) 16 | { 17 | if (m_pWebSocketServer->listen(QHostAddress::Any, port)) { 18 | if (m_debug) 19 | qDebug() << "Echoserver listening on port" << port; 20 | connect(m_pWebSocketServer, &QWebSocketServer::newConnection, 21 | this, &EchoServer::onNewConnection); 22 | connect(m_pWebSocketServer, &QWebSocketServer::closed, this, &EchoServer::closed); 23 | } 24 | } 25 | //! [constructor] 26 | 27 | EchoServer::~EchoServer() 28 | { 29 | m_pWebSocketServer->close(); 30 | qDeleteAll(m_clients.begin(), m_clients.end()); 31 | } 32 | 33 | //! [onNewConnection] 34 | void EchoServer::onNewConnection() 35 | { 36 | QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection(); 37 | 38 | connect(pSocket, &QWebSocket::textMessageReceived, this, &EchoServer::processTextMessage); 39 | connect(pSocket, &QWebSocket::binaryMessageReceived, this, &EchoServer::processBinaryMessage); 40 | connect(pSocket, &QWebSocket::disconnected, this, &EchoServer::socketDisconnected); 41 | 42 | m_clients << pSocket; 43 | } 44 | //! [onNewConnection] 45 | 46 | //! [processTextMessage] 47 | void EchoServer::processTextMessage(QString message) 48 | { 49 | QWebSocket *pClient = qobject_cast(sender()); 50 | if (m_debug) 51 | qDebug() << "Message received:" << message; 52 | if (pClient) { 53 | pClient->sendTextMessage(message); 54 | } 55 | } 56 | //! [processTextMessage] 57 | 58 | //! [processBinaryMessage] 59 | void EchoServer::processBinaryMessage(QByteArray message) 60 | { 61 | QWebSocket *pClient = qobject_cast(sender()); 62 | if (m_debug) 63 | qDebug() << "Binary Message received:" << message; 64 | if (pClient) { 65 | pClient->sendBinaryMessage(message); 66 | } 67 | } 68 | //! [processBinaryMessage] 69 | 70 | //! [socketDisconnected] 71 | void EchoServer::socketDisconnected() 72 | { 73 | QWebSocket *pClient = qobject_cast(sender()); 74 | if (m_debug) 75 | qDebug() << "socketDisconnected:" << pClient; 76 | if (pClient) { 77 | m_clients.removeAll(pClient); 78 | pClient->deleteLater(); 79 | } 80 | } 81 | //! [socketDisconnected] 82 | -------------------------------------------------------------------------------- /examples/websockets/echoserver/echoserver.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #ifndef ECHOSERVER_H 4 | #define ECHOSERVER_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | QT_FORWARD_DECLARE_CLASS(QWebSocketServer) 11 | QT_FORWARD_DECLARE_CLASS(QWebSocket) 12 | 13 | class EchoServer : public QObject 14 | { 15 | Q_OBJECT 16 | public: 17 | explicit EchoServer(quint16 port, bool debug = false, QObject *parent = nullptr); 18 | ~EchoServer(); 19 | 20 | Q_SIGNALS: 21 | void closed(); 22 | 23 | private Q_SLOTS: 24 | void onNewConnection(); 25 | void processTextMessage(QString message); 26 | void processBinaryMessage(QByteArray message); 27 | void socketDisconnected(); 28 | 29 | private: 30 | QWebSocketServer *m_pWebSocketServer; 31 | QList m_clients; 32 | bool m_debug; 33 | }; 34 | 35 | #endif //ECHOSERVER_H 36 | -------------------------------------------------------------------------------- /examples/websockets/echoserver/echoserver.pro: -------------------------------------------------------------------------------- 1 | QT = websockets 2 | 3 | TARGET = echoserver 4 | CONFIG += console 5 | CONFIG -= app_bundle 6 | 7 | TEMPLATE = app 8 | 9 | SOURCES += \ 10 | main.cpp \ 11 | echoserver.cpp 12 | 13 | HEADERS += \ 14 | echoserver.h 15 | 16 | EXAMPLE_FILES += echoclient.html 17 | 18 | target.path = $$[QT_INSTALL_EXAMPLES]/websockets/echoserver 19 | INSTALLS += target 20 | -------------------------------------------------------------------------------- /examples/websockets/echoserver/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include 4 | #include 5 | #include 6 | #include "echoserver.h" 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | QCoreApplication a(argc, argv); 11 | 12 | QCommandLineParser parser; 13 | parser.setApplicationDescription("QtWebSockets example: echoserver"); 14 | parser.addHelpOption(); 15 | 16 | QCommandLineOption dbgOption(QStringList() << "d" << "debug", 17 | QCoreApplication::translate("main", "Debug output [default: off].")); 18 | parser.addOption(dbgOption); 19 | QCommandLineOption portOption(QStringList() << "p" << "port", 20 | QCoreApplication::translate("main", "Port for echoserver [default: 1234]."), 21 | QCoreApplication::translate("main", "port"), QLatin1String("1234")); 22 | parser.addOption(portOption); 23 | parser.process(a); 24 | bool debug = parser.isSet(dbgOption); 25 | int port = parser.value(portOption).toInt(); 26 | 27 | EchoServer *server = new EchoServer(port, debug); 28 | QObject::connect(server, &EchoServer::closed, &a, &QCoreApplication::quit); 29 | 30 | return a.exec(); 31 | } 32 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketclient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(qmlwebsocketclient LANGUAGES CXX) 6 | 7 | set(CMAKE_AUTOMOC ON) 8 | 9 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 10 | set(INSTALL_EXAMPLESDIR "examples") 11 | endif() 12 | 13 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/qmlwebsocketclient") 14 | 15 | find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick WebSockets) 16 | 17 | qt_add_executable(qmlwebsocketclient 18 | main.cpp 19 | ) 20 | 21 | set_target_properties(qmlwebsocketclient PROPERTIES 22 | WIN32_EXECUTABLE TRUE 23 | MACOSX_BUNDLE FALSE 24 | ) 25 | 26 | target_link_libraries(qmlwebsocketclient PUBLIC 27 | Qt::Core 28 | Qt::Gui 29 | Qt::Quick 30 | Qt::WebSockets 31 | ) 32 | 33 | # Resources: 34 | set(data_resource_files 35 | "qml/qmlwebsocketclient/main.qml" 36 | ) 37 | 38 | qt6_add_resources(qmlwebsocketclient "data" 39 | PREFIX 40 | "/" 41 | FILES 42 | ${data_resource_files} 43 | ) 44 | 45 | install(TARGETS qmlwebsocketclient 46 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 47 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 48 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 49 | ) 50 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketclient/data.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qml/qmlwebsocketclient/main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketclient/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QGuiApplication app(argc, argv); 10 | 11 | QQuickView view; 12 | view.setSource(QUrl(QStringLiteral("qrc:/qml/qmlwebsocketclient/main.qml"))); 13 | view.show(); 14 | 15 | return app.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketclient/qml/qmlwebsocketclient/main.qml: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | import QtQuick 4 | import QtWebSockets 5 | 6 | Rectangle { 7 | width: 640 8 | height: 360 9 | 10 | WebSocket { 11 | id: socket 12 | url: "ws://ws.ifelse.io" 13 | onTextMessageReceived: function(message) { 14 | messageBox.text = messageBox.text + "\nReceived message: " + message 15 | } 16 | onStatusChanged: if (socket.status == WebSocket.Error) { 17 | console.log("Error: " + socket.errorString) 18 | } else if (socket.status == WebSocket.Open) { 19 | socket.sendTextMessage("Hello World") 20 | } else if (socket.status == WebSocket.Closed) { 21 | messageBox.text += "\nSocket closed" 22 | } 23 | active: false 24 | } 25 | 26 | WebSocket { 27 | id: secureWebSocket 28 | url: "wss://ws.ifelse.io" 29 | onTextMessageReceived: function(message) { 30 | messageBox.text = messageBox.text + "\nReceived secure message: " + message 31 | } 32 | onStatusChanged: if (secureWebSocket.status == WebSocket.Error) { 33 | console.log("Error: " + secureWebSocket.errorString) 34 | } else if (secureWebSocket.status == WebSocket.Open) { 35 | secureWebSocket.sendTextMessage("Hello Secure World") 36 | } else if (secureWebSocket.status == WebSocket.Closed) { 37 | messageBox.text += "\nSecure socket closed" 38 | } 39 | active: false 40 | } 41 | Text { 42 | id: messageBox 43 | text: socket.status == WebSocket.Open ? qsTr("Sending...") : qsTr("Welcome!") 44 | anchors.centerIn: parent 45 | } 46 | 47 | MouseArea { 48 | anchors.fill: parent 49 | onClicked: { 50 | socket.active = !socket.active 51 | secureWebSocket.active = !secureWebSocket.active; 52 | //Qt.quit(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketclient/qmlwebsocketclient.pro: -------------------------------------------------------------------------------- 1 | QT += quick websockets 2 | 3 | TARGET = qmlwebsocketclient 4 | 5 | TEMPLATE = app 6 | 7 | CONFIG -= app_bundle 8 | 9 | SOURCES += main.cpp 10 | 11 | RESOURCES += data.qrc 12 | 13 | OTHER_FILES += qml/qmlwebsocketclient/main.qml 14 | 15 | target.path = $$[QT_INSTALL_EXAMPLES]/websockets/qmlwebsocketclient 16 | INSTALLS += target 17 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketserver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(qmlwebsocketserver LANGUAGES CXX) 6 | 7 | set(CMAKE_AUTOMOC ON) 8 | 9 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 10 | set(INSTALL_EXAMPLESDIR "examples") 11 | endif() 12 | 13 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/qmlwebsocketserver") 14 | 15 | find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick WebSockets) 16 | 17 | qt_add_executable(qmlwebsocketserver 18 | main.cpp 19 | ) 20 | 21 | set_target_properties(qmlwebsocketserver PROPERTIES 22 | WIN32_EXECUTABLE TRUE 23 | MACOSX_BUNDLE FALSE 24 | ) 25 | 26 | target_link_libraries(qmlwebsocketserver PUBLIC 27 | Qt::Core 28 | Qt::Gui 29 | Qt::Quick 30 | Qt::WebSockets 31 | ) 32 | 33 | # Resources: 34 | set(data_resource_files 35 | "qml/qmlwebsocketserver/main.qml" 36 | ) 37 | 38 | qt6_add_resources(qmlwebsocketserver "data" 39 | PREFIX 40 | "/" 41 | FILES 42 | ${data_resource_files} 43 | ) 44 | 45 | install(TARGETS qmlwebsocketserver 46 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 47 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 48 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 49 | ) 50 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketserver/data.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qml/qmlwebsocketserver/main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketserver/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QGuiApplication app(argc, argv); 10 | 11 | QQuickView view; 12 | view.setSource(QUrl(QStringLiteral("qrc:/qml/qmlwebsocketserver/main.qml"))); 13 | view.show(); 14 | 15 | return app.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketserver/qml/qmlwebsocketserver/main.qml: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | import QtQuick 5 | import QtWebSockets 6 | 7 | Rectangle { 8 | width: 360 9 | height: 360 10 | 11 | function appendMessage(message) { 12 | messageBox.text += "\n" + message 13 | } 14 | 15 | WebSocketServer { 16 | id: server 17 | listen: true 18 | onClientConnected: function(webSocket) { 19 | webSocket.onTextMessageReceived.connect(function(message) { 20 | appendMessage(qsTr("Server received message: %1").arg(message)); 21 | webSocket.sendTextMessage(qsTr("Hello Client!")); 22 | }); 23 | } 24 | onErrorStringChanged: { 25 | appendMessage(qsTr("Server error: %1").arg(errorString)); 26 | } 27 | } 28 | 29 | WebSocket { 30 | id: socket 31 | url: server.url 32 | onTextMessageReceived: function(message) { 33 | appendMessage(qsTr("Client received message: %1").arg(message)); 34 | } 35 | onStatusChanged: { 36 | if (socket.status == WebSocket.Error) { 37 | appendMessage(qsTr("Client error: %1").arg(socket.errorString)); 38 | } else if (socket.status == WebSocket.Closed) { 39 | appendMessage(qsTr("Client socket closed.")); 40 | } 41 | } 42 | } 43 | 44 | Timer { 45 | interval: 100 46 | running: true 47 | onTriggered: { 48 | socket.active = true; 49 | } 50 | } 51 | 52 | Text { 53 | id: messageBox 54 | text: qsTr("Click to send a message!") 55 | anchors.fill: parent 56 | 57 | MouseArea { 58 | anchors.fill: parent 59 | onClicked: { 60 | socket.sendTextMessage(qsTr("Hello Server!")); 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /examples/websockets/qmlwebsocketserver/qmlwebsocketserver.pro: -------------------------------------------------------------------------------- 1 | QT += quick websockets 2 | 3 | TARGET = qmlwebsocketserver 4 | 5 | TEMPLATE = app 6 | 7 | CONFIG -= app_bundle 8 | 9 | SOURCES += main.cpp 10 | 11 | RESOURCES += data.qrc 12 | 13 | OTHER_FILES += qml/qmlwebsocketserver/main.qml 14 | 15 | target.path = $$[QT_INSTALL_EXAMPLES]/websockets/qmlwebsocketserver 16 | INSTALLS += target 17 | -------------------------------------------------------------------------------- /examples/websockets/simplechat/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(simplechatserver LANGUAGES CXX) 6 | 7 | if (ANDROID) 8 | message(FATAL_ERROR "This project cannot be built on Android.") 9 | endif() 10 | 11 | set(CMAKE_AUTOMOC ON) 12 | 13 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 14 | set(INSTALL_EXAMPLESDIR "examples") 15 | endif() 16 | 17 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/simplechat") 18 | 19 | find_package(Qt6 REQUIRED COMPONENTS WebSockets) 20 | 21 | qt_add_executable(simplechatserver 22 | chatserver.cpp chatserver.h 23 | main.cpp 24 | ) 25 | 26 | set_target_properties(simplechatserver PROPERTIES 27 | WIN32_EXECUTABLE FALSE 28 | MACOSX_BUNDLE FALSE 29 | ) 30 | 31 | target_link_libraries(simplechatserver PUBLIC 32 | Qt::WebSockets 33 | ) 34 | 35 | install(TARGETS simplechatserver 36 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 37 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 38 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 39 | ) 40 | -------------------------------------------------------------------------------- /examples/websockets/simplechat/chatserver.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include "chatserver.h" 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | using namespace std; 10 | 11 | QT_USE_NAMESPACE 12 | 13 | static QString getIdentifier(QWebSocket *peer) 14 | { 15 | return QStringLiteral("%1:%2").arg(peer->peerAddress().toString(), 16 | QString::number(peer->peerPort())); 17 | } 18 | 19 | //! [constructor] 20 | ChatServer::ChatServer(quint16 port, QObject *parent) : 21 | QObject(parent), 22 | m_pWebSocketServer(new QWebSocketServer(QStringLiteral("Chat Server"), 23 | QWebSocketServer::NonSecureMode, 24 | this)) 25 | { 26 | if (m_pWebSocketServer->listen(QHostAddress::Any, port)) 27 | { 28 | QTextStream(stdout) << "Chat Server listening on port " << port << '\n'; 29 | connect(m_pWebSocketServer, &QWebSocketServer::newConnection, 30 | this, &ChatServer::onNewConnection); 31 | } 32 | } 33 | 34 | ChatServer::~ChatServer() 35 | { 36 | m_pWebSocketServer->close(); 37 | } 38 | //! [constructor] 39 | 40 | //! [onNewConnection] 41 | void ChatServer::onNewConnection() 42 | { 43 | auto pSocket = m_pWebSocketServer->nextPendingConnection(); 44 | QTextStream(stdout) << getIdentifier(pSocket) << " connected!\n"; 45 | pSocket->setParent(this); 46 | 47 | connect(pSocket, &QWebSocket::textMessageReceived, 48 | this, &ChatServer::processMessage); 49 | connect(pSocket, &QWebSocket::disconnected, 50 | this, &ChatServer::socketDisconnected); 51 | 52 | m_clients << pSocket; 53 | } 54 | //! [onNewConnection] 55 | 56 | //! [processMessage] 57 | void ChatServer::processMessage(const QString &message) 58 | { 59 | QWebSocket *pSender = qobject_cast(sender()); 60 | for (QWebSocket *pClient : std::as_const(m_clients)) { 61 | if (pClient != pSender) //don't echo message back to sender 62 | pClient->sendTextMessage(message); 63 | } 64 | } 65 | //! [processMessage] 66 | 67 | //! [socketDisconnected] 68 | void ChatServer::socketDisconnected() 69 | { 70 | QWebSocket *pClient = qobject_cast(sender()); 71 | QTextStream(stdout) << getIdentifier(pClient) << " disconnected!\n"; 72 | if (pClient) 73 | { 74 | m_clients.removeAll(pClient); 75 | pClient->deleteLater(); 76 | } 77 | } 78 | //! [socketDisconnected] 79 | -------------------------------------------------------------------------------- /examples/websockets/simplechat/chatserver.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #ifndef CHATSERVER_H 4 | #define CHATSERVER_H 5 | 6 | #include 7 | #include 8 | 9 | QT_FORWARD_DECLARE_CLASS(QWebSocketServer) 10 | QT_FORWARD_DECLARE_CLASS(QWebSocket) 11 | QT_FORWARD_DECLARE_CLASS(QString) 12 | 13 | class ChatServer : public QObject 14 | { 15 | Q_OBJECT 16 | public: 17 | explicit ChatServer(quint16 port, QObject *parent = nullptr); 18 | ~ChatServer() override; 19 | 20 | private slots: 21 | void onNewConnection(); 22 | void processMessage(const QString &message); 23 | void socketDisconnected(); 24 | 25 | private: 26 | QWebSocketServer *m_pWebSocketServer; 27 | QList m_clients; 28 | }; 29 | 30 | #endif //CHATSERVER_H 31 | -------------------------------------------------------------------------------- /examples/websockets/simplechat/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include 4 | 5 | #include "chatserver.h" 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QCoreApplication a(argc, argv); 10 | ChatServer server(1234); 11 | 12 | return a.exec(); 13 | } 14 | -------------------------------------------------------------------------------- /examples/websockets/simplechat/simplechat.pro: -------------------------------------------------------------------------------- 1 | QT = websockets 2 | 3 | TARGET = simplechatserver 4 | CONFIG += console 5 | CONFIG -= app_bundle 6 | 7 | TEMPLATE = app 8 | 9 | SOURCES += \ 10 | main.cpp \ 11 | chatserver.cpp 12 | 13 | HEADERS += \ 14 | chatserver.h 15 | 16 | EXAMPLE_FILES += chatclient.html 17 | 18 | target.path = $$[QT_INSTALL_EXAMPLES]/websockets/simplechat 19 | INSTALLS += target 20 | -------------------------------------------------------------------------------- /examples/websockets/sslechoclient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(sslechoclient LANGUAGES CXX) 6 | 7 | if (ANDROID) 8 | message(FATAL_ERROR "This project cannot be built on Android.") 9 | endif() 10 | 11 | set(CMAKE_AUTOMOC ON) 12 | 13 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 14 | set(INSTALL_EXAMPLESDIR "examples") 15 | endif() 16 | 17 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/sslechoclient") 18 | 19 | find_package(Qt6 REQUIRED COMPONENTS WebSockets) 20 | 21 | qt_add_executable(sslechoclient 22 | main.cpp 23 | sslechoclient.cpp sslechoclient.h 24 | ) 25 | 26 | qt_add_resources(sslechoclient "cert" 27 | BASE ../sslechoserver 28 | FILES ../sslechoserver/localhost.cert 29 | ) 30 | 31 | set_target_properties(sslechoclient PROPERTIES 32 | WIN32_EXECUTABLE FALSE 33 | MACOSX_BUNDLE FALSE 34 | ) 35 | 36 | target_link_libraries(sslechoclient PUBLIC 37 | Qt::WebSockets 38 | ) 39 | 40 | install(TARGETS sslechoclient 41 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 42 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 43 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 44 | ) 45 | -------------------------------------------------------------------------------- /examples/websockets/sslechoclient/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include 4 | #include 5 | #include 6 | #include "sslechoclient.h" 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | using namespace Qt::Literals::StringLiterals; 11 | QCoreApplication a(argc, argv); 12 | 13 | QCommandLineParser parser; 14 | parser.setApplicationDescription("QtWebSockets example: sslechoclient"); 15 | parser.addHelpOption(); 16 | 17 | QCommandLineOption hostnameOption( 18 | QStringList{ u"n"_s, u"hostname"_s }, 19 | QCoreApplication::translate("main", "Hostname [default: localhost]."), "hostname", 20 | "localhost"); 21 | parser.addOption(hostnameOption); 22 | QCommandLineOption portOption(QStringList{ u"p"_s, u"port"_s }, 23 | QCoreApplication::translate("main", "Port [default: 1234]."), 24 | "port", "1234"); 25 | parser.addOption(portOption); 26 | 27 | parser.process(a); 28 | bool ok = true; 29 | int port = parser.value(portOption).toInt(&ok); 30 | if (!ok || port < 1 || port > 65535) { 31 | qWarning("Port invalid, must be a number between 1 and 65535\n%s", 32 | qPrintable(parser.helpText())); 33 | return 1; 34 | } 35 | QUrl url; 36 | url.setScheme(u"wss"_s); 37 | url.setHost(parser.value(hostnameOption)); 38 | url.setPort(port); 39 | SslEchoClient client(url); 40 | Q_UNUSED(client); 41 | 42 | return a.exec(); 43 | } 44 | -------------------------------------------------------------------------------- /examples/websockets/sslechoclient/sslechoclient.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include "sslechoclient.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | QT_USE_NAMESPACE 10 | 11 | //! [constructor] 12 | SslEchoClient::SslEchoClient(const QUrl &url, QObject *parent) : 13 | QObject(parent) 14 | { 15 | connect(&m_webSocket, &QWebSocket::connected, this, &SslEchoClient::onConnected); 16 | connect(&m_webSocket, QOverload&>::of(&QWebSocket::sslErrors), 17 | this, &SslEchoClient::onSslErrors); 18 | 19 | QSslConfiguration sslConfiguration; 20 | QFile certFile(QStringLiteral(":/localhost.cert")); 21 | certFile.open(QIODevice::ReadOnly); 22 | QSslCertificate certificate(&certFile, QSsl::Pem); 23 | certFile.close(); 24 | sslConfiguration.addCaCertificate(certificate); 25 | m_webSocket.setSslConfiguration(sslConfiguration); 26 | 27 | m_webSocket.open(url); 28 | } 29 | //! [constructor] 30 | 31 | //! [onConnected] 32 | void SslEchoClient::onConnected() 33 | { 34 | qDebug() << "WebSocket connected"; 35 | connect(&m_webSocket, &QWebSocket::textMessageReceived, 36 | this, &SslEchoClient::onTextMessageReceived); 37 | m_webSocket.sendTextMessage(QStringLiteral("Hello, world!")); 38 | } 39 | //! [onConnected] 40 | 41 | //! [onTextMessageReceived] 42 | void SslEchoClient::onTextMessageReceived(QString message) 43 | { 44 | qDebug() << "Message received:" << message; 45 | qApp->quit(); 46 | } 47 | 48 | void SslEchoClient::onSslErrors(const QList &errors) 49 | { 50 | qWarning() << "SSL errors:" << errors; 51 | 52 | qApp->quit(); 53 | } 54 | //! [onTextMessageReceived] 55 | -------------------------------------------------------------------------------- /examples/websockets/sslechoclient/sslechoclient.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #ifndef SSLECHOCLIENT_H 4 | #define SSLECHOCLIENT_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | QT_FORWARD_DECLARE_CLASS(QWebSocket) 14 | 15 | class SslEchoClient : public QObject 16 | { 17 | Q_OBJECT 18 | public: 19 | explicit SslEchoClient(const QUrl &url, QObject *parent = nullptr); 20 | 21 | private Q_SLOTS: 22 | void onConnected(); 23 | void onTextMessageReceived(QString message); 24 | void onSslErrors(const QList &errors); 25 | 26 | private: 27 | QWebSocket m_webSocket; 28 | }; 29 | 30 | #endif // SSLECHOCLIENT_H 31 | -------------------------------------------------------------------------------- /examples/websockets/sslechoclient/sslechoclient.pro: -------------------------------------------------------------------------------- 1 | QT = websockets 2 | 3 | TARGET = sslechoclient 4 | CONFIG += console 5 | CONFIG -= app_bundle 6 | 7 | TEMPLATE = app 8 | 9 | SOURCES += \ 10 | main.cpp \ 11 | sslechoclient.cpp 12 | 13 | HEADERS += \ 14 | sslechoclient.h 15 | 16 | resources.files = ../sslechoserver/localhost.cert 17 | resources.prefix = / 18 | 19 | RESOURCES += resources 20 | 21 | target.path = $$[QT_INSTALL_EXAMPLES]/websockets/sslechoclient 22 | INSTALLS += target 23 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(sslechoserver LANGUAGES CXX) 6 | 7 | if (ANDROID) 8 | message(FATAL_ERROR "This project cannot be built on Android.") 9 | endif() 10 | 11 | set(CMAKE_AUTOMOC ON) 12 | 13 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 14 | set(INSTALL_EXAMPLESDIR "examples") 15 | endif() 16 | 17 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/websockets/sslechoserver") 18 | 19 | find_package(Qt6 REQUIRED COMPONENTS WebSockets) 20 | 21 | qt_add_executable(sslechoserver 22 | main.cpp 23 | sslechoserver.cpp sslechoserver.h 24 | ) 25 | 26 | set_target_properties(sslechoserver PROPERTIES 27 | WIN32_EXECUTABLE FALSE 28 | MACOSX_BUNDLE FALSE 29 | ) 30 | 31 | target_link_libraries(sslechoserver PUBLIC 32 | Qt::WebSockets 33 | ) 34 | 35 | # Resources: 36 | set(securesocketclient_resource_files 37 | "localhost.cert" 38 | "localhost.key" 39 | ) 40 | 41 | qt6_add_resources(sslechoserver "securesocketclient" 42 | PREFIX 43 | "/" 44 | FILES 45 | ${securesocketclient_resource_files} 46 | ) 47 | 48 | install(TARGETS sslechoserver 49 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 50 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 51 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 52 | ) 53 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/generate.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/sh 2 | # Copyright (C) 2024 The Qt Company Ltd. 3 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 4 | 5 | openssl req -x509 -nodes -newkey rsa:4096 -keyout localhost.key -out localhost.cert -sha512 -days 365 -subj "/C=NO/ST=Oslo/L=Oslo/O=The Qt Project/OU=WebSockets/CN=localhost" 6 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/localhost.cert: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFuzCCA6OgAwIBAgIUMrxsW65722LF1Monsslw8osKQPowDQYJKoZIhvcNAQEN 3 | BQAwbTELMAkGA1UEBhMCTk8xDTALBgNVBAgMBE9zbG8xDTALBgNVBAcMBE9zbG8x 4 | FzAVBgNVBAoMDlRoZSBRdCBQcm9qZWN0MRMwEQYDVQQLDApXZWJTb2NrZXRzMRIw 5 | EAYDVQQDDAlsb2NhbGhvc3QwHhcNMjQwMzE4MTExNDU0WhcNMjUwMzE4MTExNDU0 6 | WjBtMQswCQYDVQQGEwJOTzENMAsGA1UECAwET3NsbzENMAsGA1UEBwwET3NsbzEX 7 | MBUGA1UECgwOVGhlIFF0IFByb2plY3QxEzARBgNVBAsMCldlYlNvY2tldHMxEjAQ 8 | BgNVBAMMCWxvY2FsaG9zdDCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIB 9 | ALWkKxZ2Gfv6YKz/jvl8uu8BSb7JVqhP3A1xGysHYL1K4ctYSFQsCrf6gQawkO1B 10 | mZegqPHlMy3zWFXb5XLCrFwMJo69/9iYNidXj7jHHbBI/WW53wy7ZEW0m8qhVkU6 11 | ah6wa3iAP1/4U+ovC82T+7rXvqFUjbmrXUYfJftkznTYo79uUWUI7hRTYfPqzIE0 12 | 8KsiwTKnKEEetsv6fsm30h4hJA2XvDIxiShlOFgl6BWRTOE522k+Ykxf2NqVflnn 13 | +fF7u5VOL1sAELEW4P4p6lIbzDlAKOjr9JjgMPVS5o6bH/VO0W2IRRQ28gAHBdBl 14 | Z4ftOhsDb2kbpEb+ay72u2rcpB+/zDyrZ/KeU6hsbZX2ki5tBkPZj8/rRkylm6FH 15 | 3rkG1qfGfFZrhbh5lM3g4sVu6odlD8tAxToJTUjDotilcV0L1MzU3W1ATemILekA 16 | 4O7QTnTc1+EoaqoDQJiTWqWLFJLr6vHRkicfbSGSLJskJ+n9ahwC+kMSVAbD160v 17 | dEmgpXq2FiApXpy1YfqOFGKxAbUjELf/Qad5K+xaVbnM9McUzHrZFIM7UhvBSofN 18 | 3nkiG/ckWqsUKD+EyZLZARb0oF9p0qwlUb/SOXcXRFe4FyXehUzsEdxL4BOIJ5GU 19 | T/oezLmvhvUpDPqLRADDxkF2TXd3+h9O4zxN/nwK8ISvAgMBAAGjUzBRMB0GA1Ud 20 | DgQWBBTZA6a9VA+TrBU/vt6n78GAWW0XAjAfBgNVHSMEGDAWgBTZA6a9VA+TrBU/ 21 | vt6n78GAWW0XAjAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBDQUAA4ICAQCU 22 | +mA/ow0IHjFs0VYCHg/4YaSIzfiQPeyjlNCrcpQU3knUgJu63RUVz6+0+7VfadYL 23 | /Y2A8e7YNuxw0vabzxxdx2+PO9Jh0U1ho7JUjbN7j4zuw0Rq1AlaMJ1OrNgMGB5M 24 | 0+HN/u6RyzV1Na/Ov8Ahj44a/S3oIO/fM8n2951BdsB2iTLitubU+vqfIGWIj6Zk 25 | MH3dgKWRd8mo8ZGmNfVZZ3RfNIY8oHv04yIhL/NDEdg2uKlNKuQ8OIeEGmd1PAJK 26 | xcjy+1Go1alNV2SNj7eNnyGyhWbe20EKkg3BaitJYZ6ZD15Wyx+dlnqPQOgo4xY5 27 | G3oSYH0eu2cq8+ZM1UCoB+DV5wSm6I3ema0ASShQkBCqLpu9LNHbABRIi5VXKowV 28 | Mwt6o2ZaaMHtkCydjalrW/BxswLNpX+CTjcMs2lbeloGt6oAaPYOuFVvkjsoMV9e 29 | zlDgrv9EJqT5/X3OauL57V4cptl9j3StS7v0Lfst/xY7E2TeQIcRZaA7Yz969VpF 30 | ulh5s0YClyWcrBu3kvcEexLrGGd294GBt+Sd+FxrE5xlkm5FFadUJO1fFwwtxE3L 31 | BTNQ9USZ64jWAu+ix1ZzWsii9bbuJEHnksHfDLJWaUlwRrp7Tdz6n0haYk0hkbVP 32 | YEIZHQymVHs7iFU7vfoFmlCv9xftgCMRzjI8BbVCQQ== 33 | -----END CERTIFICATE----- 34 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/localhost.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQC1pCsWdhn7+mCs 3 | /475fLrvAUm+yVaoT9wNcRsrB2C9SuHLWEhULAq3+oEGsJDtQZmXoKjx5TMt81hV 4 | 2+VywqxcDCaOvf/YmDYnV4+4xx2wSP1lud8Mu2RFtJvKoVZFOmoesGt4gD9f+FPq 5 | LwvNk/u6176hVI25q11GHyX7ZM502KO/blFlCO4UU2Hz6syBNPCrIsEypyhBHrbL 6 | +n7Jt9IeISQNl7wyMYkoZThYJegVkUzhOdtpPmJMX9jalX5Z5/nxe7uVTi9bABCx 7 | FuD+KepSG8w5QCjo6/SY4DD1UuaOmx/1TtFtiEUUNvIABwXQZWeH7TobA29pG6RG 8 | /msu9rtq3KQfv8w8q2fynlOobG2V9pIubQZD2Y/P60ZMpZuhR965BtanxnxWa4W4 9 | eZTN4OLFbuqHZQ/LQMU6CU1Iw6LYpXFdC9TM1N1tQE3piC3pAODu0E503NfhKGqq 10 | A0CYk1qlixSS6+rx0ZInH20hkiybJCfp/WocAvpDElQGw9etL3RJoKV6thYgKV6c 11 | tWH6jhRisQG1IxC3/0GneSvsWlW5zPTHFMx62RSDO1IbwUqHzd55Ihv3JFqrFCg/ 12 | hMmS2QEW9KBfadKsJVG/0jl3F0RXuBcl3oVM7BHcS+ATiCeRlE/6Hsy5r4b1KQz6 13 | i0QAw8ZBdk13d/ofTuM8Tf58CvCErwIDAQABAoICAE/GRUI9JlZbdYAlUTbTiAoW 14 | J7xKEuwi/sNMjKEOQXeBXr9/C20kVqTMuUQl4dDBweItJmXuwtaIjKBQzmnjg+19 15 | TKXeXnJTD12iADYoBSr6M4gs5QBjgLt4gf+xcgE/kYHe+6RVtv/AQaKVfPqR5rn9 16 | rPSP/RqxX2q/nV/WuzHoP6qAmfDkxiNZJ6kH0z9f799JiU5kybIn+iKF5o9TU032 17 | Qi5SGM52oQWDxwY3x8FJKlm0nl+PjX57jfMaOv7jeguLyyvcxcGSusH8CV63K/lZ 18 | ygzO1+jMUIWf2QC1oxq4mIWVUzdm5Ofm5cwLSYtoLdst3holHRYtlK21aX+bz112 19 | zNUdF/uiOC1coDYnDD+lwggvcy7UDMuRYCvMzN4ksn6wuqb2TTJza8iPYTR3R5NM 20 | I62BOIcD8Zc3ZIASoy/0RgE/d09zeEKw4x8lJtc4RWMj72Ei1noxTSbMO8wHg5NE 21 | q5+kqBDwgciq/wynPEsZrcMUtXDRnMtDhv3vEN5NEiZB/D/wa0aILx5BolDUivGj 22 | hUSCXB05xPy4hvxZdivNNwttqrpdYls37CrAzOO+ARquZc9k7VqxS4sB5VxjT8W9 23 | eycNmg2KdklYRr1PKuFqTNZj7VYKmr76+PdVIq7bBNH9jF7bknBVgSVWEGFjaNye 24 | Zejc62QaAjgqmEkJoe7ZAoIBAQDjzfVG04H1eVmAgxcP3yLcmyvZVufy5B14hu+i 25 | Jpjkq64ZZMx3Qj+rC6/L/GzIOxeh8+FccPO9zxrt+xBVpN5epYyB2dljLCUMn5yy 26 | 1HjEzIfexwVqwKLOBz/3oISx4AS2skHN9IWPl++sGFd1ibGGuWddMPNMuRUpndu7 27 | eAiL7e3LSv4r8gGLcWIKztDKS+XkSlcIFlvzf0sibVtnSqrkp+T+m6ifDMH8Dpro 28 | 0TaPtZt58IRRBwicGrkpwiz7EO9ip4McAyetbL6dVsw/B0zcz/gvAf8ZZmJ9e+XV 29 | JQhX0KxKAaqPWyfxjbIwGTl7pW+LqyHw+p8dGwMzGEFZPUfTAoIBAQDMH4RCcNaV 30 | RkDqQBNbITt38XXrsrfvfz0Y8hpTVFjo9iiq4wmPNb3pZYPp8a2E8x0mHliljGJo 31 | OqiHu/6JVtn8mgL9wlu4kEZC+v529wM33gvfntpcNKyLZp/HxoiYhh8UafaJYTNb 32 | WJBnGrIzrnsYvcJZIv16H/FqyT3up0zIcwUa/7s6e7fphWUjVZpJKWM1BMgr2n7b 33 | zxxL5Wq6L+5VajyqyucpmK30CJv0ib+3xUNf7Vn8i1wcTH4dnthEKnkVLe1Y6NjA 34 | 5jB5Uzes4LmW1dxpvaZbEDbqeHjjr/jMU8jwzDGk8vXEAu0b+g1lZ83Jj55WFkB0 35 | nB2Pw6k46wI1AoIBAQDOz0bygsgD+6PmiJwiO5fhoTnAuSYgGzoqFo5srg+14apP 36 | wXPifRFiDl0Nml+DtCnzTH32t1CArAmtrXUZ23BJio+xvv2dDBGikTDoJP5y46Ah 37 | /pqLXNEwq+JFw8NT3KVK2y/kcy3hu7TJjtuviE7TmXQeZXcr2wc8XeSDICjaKCnu 38 | mml/qdf/KPMyDqn8TcUqaNb0L6BQweqLGa6WanIU3duFzfjaU/G0C+pUnMKk2uGI 39 | ZXMqQHFvjs80+uRtFeXNsXfUsYSO7B9spcUNH2qHOIL+4hgejhWyCA4SX+lgF8Ch 40 | +ztFpCLyJ4pyIiROfVVz/ev1YwGaodBYzZdeFcUjAoIBAQCiRAOd1ZmfvONp1FoO 41 | vZJKvRZisgXqS5nENOGckJbFSrn1btpwj+ZSnbKJzOeFosXvQXxyzfCEruy+SkID 42 | 55kOZ1gtZc4IIBjasjCLXb2fMdL6h4tKdU0c3A30f+yiYyxdzAaCG1T6LqNMczpq 43 | Py/38RGITnp2FOKTYzrqdvBhAJ50YgryaNtAthw6RJiLxGzq/swpoF3sWu5BnzSC 44 | oguytutXUkkFFixirF1dvgs8CYKPxV0dl6M3k89FuLpvJdxva70cSq3UWqj6KZ8+ 45 | vL6MG6JGJM8T4QXmyrI/Pepoc8pvMcPdPo8ErNbUwKjZjfVXX+YcxT+j817EpGPn 46 | rVppAoIBAASyawrxBTul1RmEyXCMjXJL3lGdhjvbYlLfeJEO5Znu7YFfX+KKZp1n 47 | Rxw3LUjXJUOUfHWuIkPOrHYsPOkja9Vew08I4QDagSqAfB13WQ356XAiUoEOitdC 48 | OWvznnwmzWwwNUHm6crFCXnRYuqgQbW+/oj+OSt0CTerU2VefcTAgkUCdrz06AhG 49 | IRyrVCLuVi4j7yr3kYfq19/leWPWekR18vldDE/TG/N7X4KS51MI4FiVi74ByQCj 50 | Md/fkV7PLPh8vOCxWsUQ6L7MTYWzrOAOYTn8nGRambaIiDGC/IsDtI4GRuMEldGY 51 | IW4Wy2xIPf0/fQSqFWTIQxVUJr1Owfs= 52 | -----END PRIVATE KEY----- 53 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include 4 | #include "sslechoserver.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QCoreApplication a(argc, argv); 9 | SslEchoServer server(1234); 10 | 11 | Q_UNUSED(server); 12 | 13 | return a.exec(); 14 | } 15 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/securesocketclient.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | localhost.cert 4 | localhost.key 5 | 6 | 7 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/sslechoclient.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WebSocket Echo Client 5 | 6 | 7 | 8 |

WebSocket Echo Client

9 |

10 | 11 | 12 | 13 |

14 |

15 | 16 |

17 |

18 | 19 | 20 |

21 | 22 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/sslechoserver.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #include "sslechoserver.h" 4 | #include "QtWebSockets/QWebSocketServer" 5 | #include "QtWebSockets/QWebSocket" 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | QT_USE_NAMESPACE 12 | 13 | //! [constructor] 14 | SslEchoServer::SslEchoServer(quint16 port, QObject *parent) : 15 | QObject(parent), 16 | m_pWebSocketServer(nullptr) 17 | { 18 | m_pWebSocketServer = new QWebSocketServer(QStringLiteral("SSL Echo Server"), 19 | QWebSocketServer::SecureMode, 20 | this); 21 | QSslConfiguration sslConfiguration; 22 | QFile certFile(QStringLiteral(":/localhost.cert")); 23 | QFile keyFile(QStringLiteral(":/localhost.key")); 24 | certFile.open(QIODevice::ReadOnly); 25 | keyFile.open(QIODevice::ReadOnly); 26 | QSslCertificate certificate(&certFile, QSsl::Pem); 27 | QSslKey sslKey(&keyFile, QSsl::Rsa, QSsl::Pem); 28 | certFile.close(); 29 | keyFile.close(); 30 | sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone); 31 | sslConfiguration.setLocalCertificate(certificate); 32 | sslConfiguration.setPrivateKey(sslKey); 33 | m_pWebSocketServer->setSslConfiguration(sslConfiguration); 34 | 35 | if (m_pWebSocketServer->listen(QHostAddress::Any, port)) 36 | { 37 | qDebug() << "SSL Echo Server listening on port" << port; 38 | connect(m_pWebSocketServer, &QWebSocketServer::newConnection, 39 | this, &SslEchoServer::onNewConnection); 40 | connect(m_pWebSocketServer, &QWebSocketServer::sslErrors, 41 | this, &SslEchoServer::onSslErrors); 42 | } 43 | } 44 | //! [constructor] 45 | 46 | SslEchoServer::~SslEchoServer() 47 | { 48 | m_pWebSocketServer->close(); 49 | qDeleteAll(m_clients.begin(), m_clients.end()); 50 | } 51 | 52 | //! [onNewConnection] 53 | void SslEchoServer::onNewConnection() 54 | { 55 | QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection(); 56 | 57 | qDebug() << "Client connected:" << pSocket->peerName() << pSocket->origin(); 58 | 59 | connect(pSocket, &QWebSocket::textMessageReceived, this, &SslEchoServer::processTextMessage); 60 | connect(pSocket, &QWebSocket::binaryMessageReceived, 61 | this, &SslEchoServer::processBinaryMessage); 62 | connect(pSocket, &QWebSocket::disconnected, this, &SslEchoServer::socketDisconnected); 63 | 64 | m_clients << pSocket; 65 | } 66 | //! [onNewConnection] 67 | 68 | //! [processTextMessage] 69 | void SslEchoServer::processTextMessage(QString message) 70 | { 71 | QWebSocket *pClient = qobject_cast(sender()); 72 | if (pClient) 73 | { 74 | pClient->sendTextMessage(message); 75 | } 76 | } 77 | //! [processTextMessage] 78 | 79 | //! [processBinaryMessage] 80 | void SslEchoServer::processBinaryMessage(QByteArray message) 81 | { 82 | QWebSocket *pClient = qobject_cast(sender()); 83 | if (pClient) 84 | { 85 | pClient->sendBinaryMessage(message); 86 | } 87 | } 88 | //! [processBinaryMessage] 89 | 90 | //! [socketDisconnected] 91 | void SslEchoServer::socketDisconnected() 92 | { 93 | qDebug() << "Client disconnected"; 94 | QWebSocket *pClient = qobject_cast(sender()); 95 | if (pClient) 96 | { 97 | m_clients.removeAll(pClient); 98 | pClient->deleteLater(); 99 | } 100 | } 101 | 102 | void SslEchoServer::onSslErrors(const QList &) 103 | { 104 | qDebug() << "Ssl errors occurred"; 105 | } 106 | //! [socketDisconnected] 107 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/sslechoserver.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | #ifndef SSLECHOSERVER_H 4 | #define SSLECHOSERVER_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | QT_FORWARD_DECLARE_CLASS(QWebSocketServer) 12 | QT_FORWARD_DECLARE_CLASS(QWebSocket) 13 | 14 | class SslEchoServer : public QObject 15 | { 16 | Q_OBJECT 17 | public: 18 | explicit SslEchoServer(quint16 port, QObject *parent = nullptr); 19 | ~SslEchoServer() override; 20 | 21 | private Q_SLOTS: 22 | void onNewConnection(); 23 | void processTextMessage(QString message); 24 | void processBinaryMessage(QByteArray message); 25 | void socketDisconnected(); 26 | void onSslErrors(const QList &errors); 27 | 28 | private: 29 | QWebSocketServer *m_pWebSocketServer; 30 | QList m_clients; 31 | }; 32 | 33 | #endif //SSLECHOSERVER_H 34 | -------------------------------------------------------------------------------- /examples/websockets/sslechoserver/sslechoserver.pro: -------------------------------------------------------------------------------- 1 | QT = websockets 2 | 3 | TARGET = sslechoserver 4 | CONFIG += console 5 | CONFIG -= app_bundle 6 | 7 | TEMPLATE = app 8 | 9 | SOURCES += \ 10 | main.cpp \ 11 | sslechoserver.cpp 12 | 13 | HEADERS += \ 14 | sslechoserver.h 15 | 16 | EXAMPLE_FILES += sslechoclient.html 17 | 18 | RESOURCES += securesocketclient.qrc 19 | 20 | target.path = $$[QT_INSTALL_EXAMPLES]/websockets/sslechoserver 21 | INSTALLS += target 22 | -------------------------------------------------------------------------------- /examples/websockets/websockets.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | QT_FOR_CONFIG += network 3 | 4 | SUBDIRS = echoclient \ 5 | echoserver \ 6 | simplechat 7 | 8 | qtHaveModule(quick) { 9 | SUBDIRS += qmlwebsocketclient \ 10 | qmlwebsocketserver 11 | } 12 | 13 | qtConfig(ssl) { 14 | SUBDIRS += \ 15 | sslechoserver \ 16 | sslechoclient 17 | } 18 | -------------------------------------------------------------------------------- /qtwebsockets.pro: -------------------------------------------------------------------------------- 1 | requires(qtHaveModule(network)) 2 | load(qt_parts) 3 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from src.pro. 5 | 6 | add_subdirectory(websockets) 7 | if(TARGET Qt::Quick) 8 | add_subdirectory(imports) 9 | endif() 10 | -------------------------------------------------------------------------------- /src/imports/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from imports.pro. 5 | 6 | add_subdirectory(qmlwebsockets) 7 | -------------------------------------------------------------------------------- /src/imports/qmlwebsockets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | qt_internal_add_qml_module(qmlwebsockets 5 | URI "QtWebSockets" 6 | VERSION "${PROJECT_VERSION}" 7 | PAST_MAJOR_VERSIONS 1 8 | CLASS_NAME QtWebSocketsDeclarativeModule 9 | PLUGIN_TARGET qmlwebsockets 10 | NO_PLUGIN_OPTIONAL 11 | NO_GENERATE_PLUGIN_SOURCE 12 | NO_GENERATE_QMLTYPES 13 | INSTALL_SOURCE_QMLTYPES "plugins.qmltypes" 14 | SOURCES 15 | qmlwebsockets_plugin.cpp qmlwebsockets_plugin.h 16 | qqmlwebsocket.cpp qqmlwebsocket.h 17 | qqmlwebsocketserver.cpp qqmlwebsocketserver.h 18 | DEFINES 19 | QT_NO_CONTEXTLESS_CONNECT 20 | LIBRARIES 21 | Qt::CorePrivate 22 | Qt::QmlPrivate 23 | Qt::WebSockets 24 | NO_GENERATE_CPP_EXPORTS 25 | ) 26 | -------------------------------------------------------------------------------- /src/imports/qmlwebsockets/plugins.qmltypes: -------------------------------------------------------------------------------- 1 | import QtQuick.tooling 1.2 2 | 3 | // This file describes the plugin-supplied types contained in the library. 4 | // It is used for QML tooling purposes only. 5 | // 6 | // This file was auto-generated by: 7 | // 'qmlplugindump -nonrelocatable -dependencies dependencies.json QtWebSockets 1.15' 8 | 9 | Module { 10 | dependencies: [] 11 | Component { 12 | name: "QQmlWebSocket" 13 | prototype: "QObject" 14 | exports: ["QtWebSockets/WebSocket 1.0", "QtWebSockets/WebSocket 1.1"] 15 | exportMetaObjectRevisions: [0, 1] 16 | Enum { 17 | name: "Status" 18 | values: { 19 | "Connecting": 0, 20 | "Open": 1, 21 | "Closing": 2, 22 | "Closed": 3, 23 | "Error": 4 24 | } 25 | } 26 | Property { name: "url"; type: "QUrl" } 27 | Property { name: "status"; type: "Status"; isReadonly: true } 28 | Property { name: "errorString"; type: "string"; isReadonly: true } 29 | Property { name: "active"; type: "bool" } 30 | Signal { 31 | name: "textMessageReceived" 32 | Parameter { name: "message"; type: "string" } 33 | } 34 | Signal { 35 | name: "binaryMessageReceived" 36 | revision: 1 37 | Parameter { name: "message"; type: "QByteArray" } 38 | } 39 | Signal { 40 | name: "statusChanged" 41 | Parameter { name: "status"; type: "QQmlWebSocket::Status" } 42 | } 43 | Signal { 44 | name: "activeChanged" 45 | Parameter { name: "isActive"; type: "bool" } 46 | } 47 | Signal { 48 | name: "errorStringChanged" 49 | Parameter { name: "errorString"; type: "string" } 50 | } 51 | Method { 52 | name: "sendTextMessage" 53 | type: "qlonglong" 54 | Parameter { name: "message"; type: "string" } 55 | } 56 | Method { 57 | name: "sendBinaryMessage" 58 | revision: 1 59 | type: "qlonglong" 60 | Parameter { name: "message"; type: "QByteArray" } 61 | } 62 | } 63 | Component { 64 | name: "QQmlWebSocketServer" 65 | prototype: "QObject" 66 | exports: ["QtWebSockets/WebSocketServer 1.0"] 67 | exportMetaObjectRevisions: [0] 68 | Property { name: "url"; type: "QUrl"; isReadonly: true } 69 | Property { name: "host"; type: "string" } 70 | Property { name: "port"; type: "int" } 71 | Property { name: "name"; type: "string" } 72 | Property { name: "errorString"; type: "string"; isReadonly: true } 73 | Property { name: "listen"; type: "bool" } 74 | Property { name: "accept"; type: "bool" } 75 | Signal { 76 | name: "clientConnected" 77 | Parameter { name: "webSocket"; type: "QQmlWebSocket"; isPointer: true } 78 | } 79 | Signal { 80 | name: "errorStringChanged" 81 | Parameter { name: "errorString"; type: "string" } 82 | } 83 | Signal { 84 | name: "urlChanged" 85 | Parameter { name: "url"; type: "QUrl" } 86 | } 87 | Signal { 88 | name: "portChanged" 89 | Parameter { name: "port"; type: "int" } 90 | } 91 | Signal { 92 | name: "nameChanged" 93 | Parameter { name: "name"; type: "string" } 94 | } 95 | Signal { 96 | name: "hostChanged" 97 | Parameter { name: "host"; type: "string" } 98 | } 99 | Signal { 100 | name: "listenChanged" 101 | Parameter { name: "listen"; type: "bool" } 102 | } 103 | Signal { 104 | name: "acceptChanged" 105 | Parameter { name: "accept"; type: "bool" } 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/imports/qmlwebsockets/qmlwebsockets_plugin.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #include "qmlwebsockets_plugin.h" 5 | 6 | #include 7 | 8 | #include "qqmlwebsocket.h" 9 | #include "qqmlwebsocketserver.h" 10 | 11 | QT_BEGIN_NAMESPACE 12 | 13 | void QtWebSocketsDeclarativeModule::registerTypes(const char *uri) 14 | { 15 | Q_ASSERT(uri == QLatin1String("QtWebSockets")); 16 | 17 | // @uri QtWebSockets 18 | qmlRegisterType(uri, 1 /*major*/, 0 /*minor*/, "WebSocket"); 19 | qmlRegisterType(uri, 1 /*major*/, 1 /*minor*/, "WebSocket"); 20 | qmlRegisterType(uri, 1 /*major*/, 0 /*minor*/, "WebSocketServer"); 21 | 22 | // Auto-increment the import to stay in sync with ALL future QtQuick minor versions 23 | qmlRegisterModule(uri, 1, QT_VERSION_MINOR); 24 | } 25 | 26 | QT_END_NAMESPACE 27 | -------------------------------------------------------------------------------- /src/imports/qmlwebsockets/qmlwebsockets_plugin.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #ifndef QMLWEBSOCKET_PLUGIN_H 5 | #define QMLWEBSOCKET_PLUGIN_H 6 | 7 | #include 8 | 9 | QT_BEGIN_NAMESPACE 10 | 11 | class QtWebSocketsDeclarativeModule : public QQmlExtensionPlugin 12 | { 13 | Q_OBJECT 14 | Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) 15 | 16 | public: 17 | QtWebSocketsDeclarativeModule(QObject *parent = 0) : QQmlExtensionPlugin(parent) { } 18 | void registerTypes(const char *uri) override; 19 | }; 20 | 21 | QT_END_NAMESPACE 22 | 23 | #endif // QMLWEBSOCKET_PLUGIN_H 24 | -------------------------------------------------------------------------------- /src/imports/qmlwebsockets/qqmlwebsocket.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #ifndef QQMLWEBSOCKET_H 5 | #define QQMLWEBSOCKET_H 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | QT_BEGIN_NAMESPACE 14 | 15 | class QQmlWebSocket : public QObject, public QQmlParserStatus 16 | { 17 | Q_OBJECT 18 | Q_DISABLE_COPY(QQmlWebSocket) 19 | Q_INTERFACES(QQmlParserStatus) 20 | 21 | Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) 22 | Q_PROPERTY(QStringList requestedSubprotocols READ requestedSubprotocols 23 | WRITE setRequestedSubprotocols NOTIFY requestedSubprotocolsChanged) 24 | Q_PROPERTY(Status status READ status NOTIFY statusChanged) 25 | Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged) 26 | Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) 27 | Q_PROPERTY(QString negotiatedSubprotocol READ negotiatedSubprotocol 28 | NOTIFY negotiatedSubprotocolChanged) 29 | 30 | public: 31 | explicit QQmlWebSocket(QObject *parent = 0); 32 | explicit QQmlWebSocket(QWebSocket *socket, QObject *parent = 0); 33 | ~QQmlWebSocket() override; 34 | 35 | enum Status 36 | { 37 | Connecting = 0, 38 | Open = 1, 39 | Closing = 2, 40 | Closed = 3, 41 | Error = 4 42 | }; 43 | Q_ENUM(Status) 44 | 45 | QUrl url() const; 46 | void setUrl(const QUrl &url); 47 | QStringList requestedSubprotocols() const; 48 | void setRequestedSubprotocols(const QStringList &subprotocols); 49 | 50 | QString negotiatedSubprotocol() const; 51 | Status status() const; 52 | QString errorString() const; 53 | 54 | void setActive(bool active); 55 | bool isActive() const; 56 | 57 | Q_INVOKABLE qint64 sendTextMessage(const QString &message); 58 | Q_REVISION(1) Q_INVOKABLE qint64 sendBinaryMessage(const QByteArray &message); 59 | Q_REVISION(6, 9) Q_INVOKABLE void ping(const QByteArray &payload = QByteArray()); 60 | 61 | Q_SIGNALS: 62 | void textMessageReceived(QString message); 63 | Q_REVISION(1) void binaryMessageReceived(QByteArray message); 64 | void statusChanged(QQmlWebSocket::Status status); 65 | void activeChanged(bool isActive); 66 | void errorStringChanged(QString errorString); 67 | void urlChanged(); 68 | void requestedSubprotocolsChanged(); 69 | void negotiatedSubprotocolChanged(); 70 | Q_REVISION(6, 9) void pong(quint64 elapsedTime, QByteArray payload); 71 | 72 | public: 73 | void classBegin() override; 74 | void componentComplete() override; 75 | 76 | private Q_SLOTS: 77 | void onError(QAbstractSocket::SocketError error); 78 | void onStateChanged(QAbstractSocket::SocketState state); 79 | 80 | private: 81 | QScopedPointer m_webSocket; 82 | QString m_negotiatedProtocol; 83 | Status m_status; 84 | QUrl m_url; 85 | QStringList m_requestedProtocols; 86 | bool m_isActive; 87 | bool m_componentCompleted; 88 | QString m_errorString; 89 | 90 | // takes ownership of the socket 91 | void setSocket(QWebSocket *socket); 92 | void setStatus(Status status); 93 | void open(); 94 | void close(); 95 | void setErrorString(QString errorString = QString()); 96 | }; 97 | 98 | QT_END_NAMESPACE 99 | 100 | #endif // QQMLWEBSOCKET_H 101 | -------------------------------------------------------------------------------- /src/imports/qmlwebsockets/qqmlwebsocketserver.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #ifndef QQMLWEBSOCKETSERVER_H 5 | #define QQMLWEBSOCKETSERVER_H 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | QT_BEGIN_NAMESPACE 12 | 13 | class QQmlWebSocket; 14 | class QQmlWebSocketServer : public QObject, public QQmlParserStatus 15 | { 16 | Q_OBJECT 17 | Q_DISABLE_COPY(QQmlWebSocketServer) 18 | Q_INTERFACES(QQmlParserStatus) 19 | 20 | Q_PROPERTY(QUrl url READ url NOTIFY urlChanged) 21 | Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged) 22 | Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged) 23 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 24 | Q_PROPERTY(QStringList supportedSubprotocols READ supportedSubprotocols 25 | WRITE setSupportedSubprotocols NOTIFY supportedSubprotocolsChanged) 26 | Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged) 27 | Q_PROPERTY(bool listen READ listen WRITE setListen NOTIFY listenChanged) 28 | Q_PROPERTY(bool accept READ accept WRITE setAccept NOTIFY acceptChanged) 29 | 30 | public: 31 | explicit QQmlWebSocketServer(QObject *parent = nullptr); 32 | ~QQmlWebSocketServer() override; 33 | 34 | void classBegin() override; 35 | void componentComplete() override; 36 | 37 | QUrl url() const; 38 | 39 | QString host() const; 40 | void setHost(const QString &host); 41 | 42 | int port() const; 43 | void setPort(int port); 44 | 45 | QString name() const; 46 | void setName(const QString &name); 47 | 48 | QStringList supportedSubprotocols() const; 49 | void setSupportedSubprotocols(const QStringList &supportedSubprotocols); 50 | 51 | QString errorString() const; 52 | 53 | bool listen() const; 54 | void setListen(bool listen); 55 | 56 | bool accept() const; 57 | void setAccept(bool accept); 58 | 59 | Q_SIGNALS: 60 | void clientConnected(QQmlWebSocket *webSocket); 61 | 62 | void errorStringChanged(const QString &errorString); 63 | void urlChanged(const QUrl &url); 64 | void portChanged(int port); 65 | void nameChanged(const QString &name); 66 | void supportedSubprotocolsChanged(const QStringList &supportedProtocols); 67 | void hostChanged(const QString &host); 68 | void listenChanged(bool listen); 69 | void acceptChanged(bool accept); 70 | 71 | private: 72 | void init(); 73 | void updateListening(); 74 | void newConnection(); 75 | void serverError(); 76 | void closed(); 77 | 78 | QScopedPointer m_server; 79 | QString m_host; 80 | QString m_name; 81 | QStringList m_supportedSubprotocols; 82 | int m_port; 83 | bool m_listen; 84 | bool m_accept; 85 | bool m_componentCompleted; 86 | 87 | }; 88 | 89 | QT_END_NAMESPACE 90 | 91 | #endif // QQMLWEBSOCKETSERVER_H 92 | -------------------------------------------------------------------------------- /src/websockets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from websockets.pro. 5 | 6 | ##################################################################### 7 | ## WebSockets Module: 8 | ##################################################################### 9 | 10 | qt_internal_add_module(WebSockets 11 | SOURCES 12 | qdefaultmaskgenerator_p.cpp qdefaultmaskgenerator_p.h 13 | qmaskgenerator.cpp qmaskgenerator.h 14 | qwebsocket.cpp qwebsocket.h qwebsocket_p.cpp qwebsocket_p.h 15 | qwebsocketcorsauthenticator.cpp qwebsocketcorsauthenticator.h qwebsocketcorsauthenticator_p.h 16 | qwebsocketdataprocessor.cpp qwebsocketdataprocessor_p.h 17 | qwebsocketframe.cpp qwebsocketframe_p.h 18 | qwebsockethandshakeoptions.cpp qwebsockethandshakeoptions.h qwebsockethandshakeoptions_p.h 19 | qwebsockethandshakerequest.cpp qwebsockethandshakerequest_p.h 20 | qwebsockethandshakeresponse.cpp qwebsockethandshakeresponse_p.h 21 | qwebsocketprotocol.cpp qwebsocketprotocol.h qwebsocketprotocol_p.h 22 | qwebsockets_global.h 23 | qwebsocketserver.cpp qwebsocketserver.h qwebsocketserver_p.cpp qwebsocketserver_p.h 24 | DEFINES 25 | QT_NO_CONTEXTLESS_CONNECT 26 | LIBRARIES 27 | Qt::CorePrivate 28 | Qt::NetworkPrivate 29 | PUBLIC_LIBRARIES 30 | Qt::Core 31 | Qt::Network 32 | PRIVATE_MODULE_INTERFACE 33 | Qt::CorePrivate 34 | ) 35 | 36 | #### Keys ignored in scope 1:.:.:websockets.pro:: 37 | # OTHER_FILES = "doc/src/*.qdoc" "doc/snippets/*.cpp" "doc/qtwebsockets.qdocconf" 38 | 39 | ## Scopes: 40 | ##################################################################### 41 | 42 | qt_internal_extend_target(WebSockets CONDITION WASM 43 | SOURCES 44 | qwebsocket_wasm_p.cpp 45 | LIBRARIES 46 | websocket.js 47 | ) 48 | 49 | qt_internal_add_docs(WebSockets 50 | doc/qtwebsockets.qdocconf 51 | ) 52 | 53 | -------------------------------------------------------------------------------- /src/websockets/doc/images/websockets-pictorial-representation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebsockets/638b7cd687d5077c79bb619840cfc9ea9f92c7ce/src/websockets/doc/images/websockets-pictorial-representation.jpg -------------------------------------------------------------------------------- /src/websockets/doc/qtwebsockets.qdocconf: -------------------------------------------------------------------------------- 1 | include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf) 2 | include($QT_INSTALL_DOCS/config/exampleurl-qtwebsockets.qdocconf) 3 | 4 | project = QtWebSockets 5 | description = Qt WebSockets Reference Documentation 6 | version = $QT_VERSION 7 | 8 | examplesinstallpath = websockets 9 | 10 | # Path to the root of qtwebsockets (for automatic linking to source code) 11 | url.sources.rootdir = ../../.. 12 | 13 | qhp.projects = QtWebSockets 14 | 15 | qhp.QtWebSockets.file = qtwebsockets.qhp 16 | qhp.QtWebSockets.namespace = org.qt-project.qtwebsockets.$QT_VERSION_TAG 17 | qhp.QtWebSockets.virtualFolder = qtwebsockets 18 | qhp.QtWebSockets.indexTitle = Qt WebSockets 19 | qhp.QtWebSockets.indexRoot = 20 | 21 | qhp.QtWebSockets.subprojects = manual examples classes qml 22 | 23 | qhp.QtWebSockets.subprojects.classes.title = C++ Classes 24 | qhp.QtWebSockets.subprojects.classes.indexTitle = Qt WebSockets C++ Classes 25 | qhp.QtWebSockets.subprojects.classes.selectors = class headerfile 26 | qhp.QtWebSockets.subprojects.classes.sortPages = true 27 | 28 | qhp.QtWebSockets.subprojects.qml.title = QML Types 29 | qhp.QtWebSockets.subprojects.qml.indexTitle = Qt WebSockets QML Types 30 | qhp.QtWebSockets.subprojects.qml.selectors = qmltype 31 | qhp.QtWebSockets.subprojects.qml.sortPages = true 32 | 33 | qhp.QtWebSockets.subprojects.examples.title = Examples 34 | qhp.QtWebSockets.subprojects.examples.indexTitle = Qt WebSockets Examples 35 | qhp.QtWebSockets.subprojects.examples.selectors = example 36 | qhp.QtWebSockets.subprojects.examples.sortPages = true 37 | 38 | qhp.QtWebSockets.subprojects.manual.title = Qt WebSockets 39 | qhp.QtWebSockets.subprojects.manual.indexTitle = Qt WebSockets module topics 40 | qhp.QtWebSockets.subprojects.manual.type = manual 41 | 42 | tagfile = ../../../doc/qtwebsockets/qtwebsockets.tags 43 | 44 | depends += qtcore qtnetwork qtdoc qmake qtcmake 45 | 46 | headerdirs += .. \ 47 | ../../imports 48 | 49 | sourcedirs += .. \ 50 | src \ 51 | ../../imports \ 52 | ../../../tests/doc 53 | 54 | 55 | exampledirs += ../../../examples/websockets \ 56 | snippets 57 | 58 | examples.fileextensions += "*.html" 59 | 60 | imagedirs += ../../../examples/websockets/doc/images \ 61 | images 62 | 63 | #add generic thumbnail images for example documentation that does not have an image. 64 | manifestmeta.thumbnail.names += "QtWebSockets/Echo Client*" \ 65 | "QtWebSockets/QML*" \ 66 | "QtWebSockets/SSL*" \ 67 | "QtWebSockets/Simple*" 68 | 69 | manifestmeta.highlighted.names = "QtWebSockets/Simple WebSocket Chat" 70 | 71 | navigation.landingpage = "Qt WebSockets" 72 | navigation.cppclassespage = "Qt WebSockets C++ Classes" 73 | navigation.qmltypespage = "Qt WebSockets QML Types" 74 | # Auto-generate navigation linking based on "Qt WebSockets module topics": 75 | navigation.toctitles = "Qt WebSockets module topics" 76 | navigation.toctitles.inclusive = false 77 | -------------------------------------------------------------------------------- /src/websockets/doc/snippets/src_websockets_ssl_qwebsocket.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 Kurt Pattyn 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | //! [6] 4 | QList cert = QSslCertificate::fromPath(QLatin1String("server-certificate.pem")); 5 | QSslError error(QSslError::SelfSignedCertificate, cert.at(0)); 6 | QList expectedSslErrors; 7 | expectedSslErrors.append(error); 8 | 9 | QWebSocket socket; 10 | socket.ignoreSslErrors(expectedSslErrors); 11 | socket.open(QUrl(QStringLiteral("wss://myserver.at.home"))); 12 | //! [6] 13 | -------------------------------------------------------------------------------- /src/websockets/doc/src/external-resources.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \externalpage https://www.ieee-security.org/TC/W2SP/2011/papers/websocket.pdf 6 | \title "Talking to Yourself for Fun and Profit" by Lin-Shung Huang et al 7 | */ 8 | 9 | /*! 10 | \externalpage https://datatracker.ietf.org/doc/html/rfc6454 11 | \title RFC 6454 12 | */ 13 | 14 | /*! 15 | \externalpage https://datatracker.ietf.org/doc/html/rfc6455 16 | \title RFC 6455 17 | */ 18 | 19 | /*! 20 | \externalpage https://datatracker.ietf.org/doc/html/rfc6455#section-10 21 | \title WebSocket Security Considerations 22 | */ 23 | 24 | /*! 25 | \externalpage https://datatracker.ietf.org/doc/html/rfc6455#section-9 26 | \title WebSocket Extensions 27 | */ 28 | 29 | /*! 30 | \externalpage https://datatracker.ietf.org/doc/html/rfc6455#section-1.9 31 | \title WebSocket Subprotocols 32 | */ 33 | 34 | /*! 35 | \externalpage https://datatracker.ietf.org/doc/html/draft-hixie-thewebsocketprotocol-76 36 | \title hixie76 37 | */ 38 | 39 | /*! 40 | \externalpage https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-00 41 | \title hybi-00 42 | */ 43 | 44 | /*! 45 | \externalpage https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-04 46 | \title hybi-04 47 | */ 48 | 49 | /*! 50 | \externalpage https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-05 51 | \title hybi-05 52 | */ 53 | 54 | /*! 55 | \externalpage https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-07 56 | \title hybi-07 57 | */ 58 | 59 | /*! 60 | \externalpage https://github.com/google/pywebsocket/wiki/WebSocketProtocolSpec 61 | \title pywebsocket's WebSocketProtocolSpec 62 | */ 63 | 64 | /*! 65 | \externalpage https://github.com/crossbario/autobahn-testsuite 66 | \title Autobahn|Testsuite 67 | */ 68 | 69 | /*! 70 | \externalpage https://github.com/crossbario/autobahn-testsuite/blob/master/README.md#installation 71 | \title Autobahn|Testsuite installation documentation 72 | */ 73 | 74 | /*! 75 | \externalpage https://www.mozilla.org/firefox 76 | \title Firefox 77 | */ 78 | 79 | /*! 80 | \externalpage https://bugzilla.mozilla.org/show_bug.cgi?id=594502 81 | \title Firefox bug 594502 82 | */ 83 | -------------------------------------------------------------------------------- /src/websockets/doc/src/index.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 Kurt Pattyn 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \page qtwebsockets-index.html 6 | \since 5.3 7 | \title Qt WebSockets 8 | \brief Provides an implementation of the WebSocket protocol. 9 | 10 | WebSocket is a web-based protocol designed to enable a two-way interactive 11 | communication session between a client application and a remote host. It 12 | enables the two entities to send data back and forth if the initial 13 | handshake succeeds. 14 | 15 | The Qt WebSockets module provides C++ and QML interfaces that enable 16 | Qt applications to act as a server that can process WebSocket requests, 17 | or a client that can consume data received from the server, or both. 18 | 19 | \section1 Using the Module 20 | 21 | \section2 QML API 22 | 23 | \include {module-use.qdocinc} {using the qml api} {QtWebSockets} 24 | 25 | \section2 C++ API 26 | 27 | \include {module-use.qdocinc} {using the c++ api} 28 | 29 | \section3 Building with CMake 30 | 31 | \include {module-use.qdocinc} {building with cmake} {WebSockets} 32 | 33 | \section3 Building with qmake 34 | 35 | \include {module-use.qdocinc} {building_with_qmake} {websockets} 36 | 37 | \section1 Examples 38 | 39 | \list 40 | \li \l {Qt WebSockets Examples} 41 | \endlist 42 | 43 | \section1 Reference 44 | 45 | \list 46 | \li \l {Qt WebSockets Overview} {Overview} 47 | \li \l {Qt WebSockets C++ Classes} {C++ Classes} 48 | \li \l {Qt WebSockets QML Types} {QML Types} 49 | \endlist 50 | 51 | \section1 Conformance 52 | 53 | \list 54 | \li \l {Testing Qt WebSockets} 55 | \endlist 56 | 57 | \section1 Licenses 58 | 59 | Qt WebSockets is available under commercial licenses from \l{The Qt Company}. 60 | In addition, it is available under free software licenses. Since Qt 5.4, 61 | these free software licenses are 62 | \l{GNU Lesser General Public License, version 3}, or 63 | the \l{GNU General Public License, version 2}. 64 | See \l{Qt Licensing} for further details. 65 | */ 66 | 67 | /*! 68 | \page qtwebsockets-testing.html 69 | \title Testing Qt WebSockets 70 | 71 | \l {Autobahn|Testsuite}, a standard test 72 | suite for WebSocket Protocol (\l{RFC 6455}), can be used for testing the 73 | conformance of Qt WebSockets. Refer to 74 | \l {Autobahn|Testsuite installation documentation} 75 | to set up the test suite. 76 | 77 | \include README.qdocinc testsuite 78 | */ 79 | -------------------------------------------------------------------------------- /src/websockets/doc/src/overview.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \page websockets-overview.html 6 | \title Qt WebSockets Overview 7 | \brief Provides insight into the WebSocket protocol and the Qt WebSockets module. 8 | \ingroup explanations-webtechnologies 9 | 10 | Qt WebSockets enables you to build WebSocket-aware applications. It 11 | provides an implementation for the WebSocket protocol, which is offered by IETF 12 | (Internet Engineering Task Force) as a better alternative for bidirectional 13 | communication using the existing web infrastructure. 14 | 15 | Historically, web applications that needed bidirectional communication or 16 | push notifications had to use one of the HTTP-based solutions available. These 17 | solutions employed different techniques such as polling, long-polling, and 18 | streaming, to overcome the limitations of HTTP protocol, which is not designed 19 | for such use cases. This resulted in high network latency, unnecessary data 20 | exchange, and stale or old data. The WebSocket offering by IETF helps to 21 | overcome these problems to a large extent. 22 | 23 | \section1 How does it Work? 24 | 25 | \image websockets-pictorial-representation.jpg 26 | 27 | As you can see in the pictorial representation, WebSocket-based solution 28 | consists of a client-side and server-side. The native client-side support for 29 | WebSocket is available on most of the popular web browsers such as Google 30 | Chrome, Internet Explorer, Safari, and so on. The server-side support for 31 | WebSocket makes it a complete solution, enabling bidirectional communication. 32 | Any browser with native WebSocket support should let you run a simple HTML and 33 | JavaScript-based client application using the HTML5 WebSocket API. 34 | 35 | A WebSocket connection begins with a initial HTTP-compatible handshake, 36 | which ensures backwards compatibility so that the WebSocket connections can 37 | share the default HTTP (80) and HTTPS (443) ports. On successful handshake, 38 | the connection is open for data exchange, until one of the two entities end 39 | the connection. 40 | 41 | The WebSocket protocol uses \c ws: and \c wss: URL schemes to represent 42 | unsecure and secure WebSocket requests, respectively. During the initial 43 | handshake, if a proxy server is detected, the protocol tries to set up a tunnel 44 | by issuing an \c{HTTP CONNECT} statement to the proxy. The tunnel approach to 45 | handle proxies is used irrespective of the request type, although it is proved 46 | to work better with TLS (Transport Layer Security) in secure connections. 47 | 48 | \section1 Typical Use Cases 49 | 50 | WebSocket suits best for scenarios where, 51 | \list 52 | \li data presented must be up-to-date, 53 | \li low network latency and minimal data exchange is crucial. 54 | \endlist 55 | 56 | A few example applications where we struggle to achieve these using the 57 | traditional approach are, instant messaging, online gaming, online stock 58 | trading, and so on. 59 | 60 | \section1 Role of Qt WebSockets 61 | 62 | The Qt WebSockets module provides APIs to develop WebSocket-based server and 63 | client applications. An example of where these APIs can be used is a server 64 | application that provides stock data, and a client application that registers 65 | for push notification when there is a change in price of a few stocks. 66 | 67 | The module provides both C++ and QML versions of the API, so you can choose 68 | the alternative that suits your need. 69 | 70 | \section2 Qt WebSockets with Cloud Services 71 | 72 | The client application usually depends on an external service for data. Most of 73 | these service providers do not support WebSocket yet, so you end up developing 74 | a WebSocket-aware server application to bridge the gap. You can run the server 75 | on an enterprise WebSocket gateway service such as a cloud service, avoiding 76 | the hassle of maintaining the necessary infrastructure required to host such 77 | a service. 78 | 79 | Most of the cloud Services provide a Platform as a service (PaaS) backend, 80 | which enables deploying and running an instance of your server application on 81 | the cloud. The client applications can connect to the running server using a 82 | WebSocket URL and receive data. 83 | 84 | \section2 Related Information 85 | \list 86 | \li \l{RFC 6455} 87 | \endlist 88 | */ 89 | -------------------------------------------------------------------------------- /src/websockets/doc/src/qt6-changes.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2021 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \page qtwebsockets-changes-qt6.html 6 | \title Changes to Qt WebSockets 7 | \ingroup changes-qt-5-to-6 8 | \brief Migrate Qt WebSockets to Qt 6. 9 | 10 | Qt 6 is a result of the conscious effort to make the framework more 11 | efficient and easy to use. 12 | 13 | We try to maintain binary and source compatibility for all the public 14 | APIs in each release. But some changes were inevitable in an effort to 15 | make Qt a better framework. 16 | 17 | In this topic we summarize those changes in Qt WebSockets, and provide guidance 18 | to handle them. 19 | 20 | \section1 Breaking public API changes 21 | 22 | This section contains information about API changes that break source 23 | compatibility. 24 | 25 | \section2 QWebSocketServer::socketDescriptor(), QWebSocketServer::setSocketDescriptor() 26 | 27 | In Qt 6, you should use QWebSocketServer::socketDescriptor() and QWebSocketServer::setSocketDescriptor() 28 | to access the underlying socket descriptor of type \c{qintptr}. They mirror QTcpServer::socketDescriptor() 29 | and QTcpServer::setSocketDescriptor(), and replace the now deprecated nativeDescriptor() and 30 | setNativeDescriptor() methods. 31 | 32 | */ 33 | -------------------------------------------------------------------------------- /src/websockets/doc/src/qtwebsockets-module.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 Kurt Pattyn 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | /*! 4 | \module QtWebSockets 5 | \title Qt WebSockets C++ Classes 6 | \ingroup modules 7 | \qtcmakepackage WebSockets 8 | \qtvariable websockets 9 | \since 5.3 10 | \brief List of C++ classes that enable WebSocket-based communication. 11 | 12 | To use these classes in your application, use the following include 13 | statement: 14 | 15 | \code 16 | #include 17 | \endcode 18 | 19 | To link against the module, add this line to your \l qmake \c 20 | .pro file: 21 | 22 | \code 23 | QT += websockets 24 | \endcode 25 | */ 26 | 27 | /*! 28 | \qmlmodule QtWebSockets 1.\QtMinorVersion 29 | \title Qt WebSockets QML Types 30 | \ingroup qmlmodules 31 | \brief Provides QML types for WebSocket-based communication. 32 | 33 | 34 | The QML types are accessed by using: 35 | \qml \QtMinorVersion 36 | import QtWebSockets 1.\1 37 | \endqml 38 | 39 | \note Prior to Qt 5.5, the import statement was \c{import Qt.WebSockets 1.0} 40 | (notice the dot between \c Qt and \c WebSockets). The old statement is still 41 | supported for backwards compatibility, but it cannot be mixed with the new 42 | statement within the same project. 43 | */ 44 | -------------------------------------------------------------------------------- /src/websockets/doc/src/qtwebsockets-toc.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2024 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \page qtwebsockets-toc.html 6 | \title Qt WebSockets module topics 7 | 8 | The following list has links to all the individual topics (HTML files) 9 | in the Qt WebSockets module. 10 | 11 | \list 12 | \li \l {Qt WebSockets Overview}{Overview} 13 | \li \l {Testing Qt WebSockets} 14 | \li \l {QWebSocket client example}{WebSocket client sample} 15 | \li \l {WebSocket server example}{WebSocket server sample} 16 | \li \l {Changes to Qt WebSockets}{Upgrading from Qt 5} 17 | \endlist 18 | 19 | */ 20 | -------------------------------------------------------------------------------- /src/websockets/qdefaultmaskgenerator_p.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | /*! 4 | \class QDefaultMaskGenerator 5 | 6 | \inmodule QtWebSockets 7 | 8 | \brief The QDefaultMaskGenerator class provides the default mask generator for QtWebSockets. 9 | 10 | The WebSockets specification as outlined in \l {RFC 6455} 11 | requires that all communication from client to server must be masked. This is to prevent 12 | malicious scripts to attack bad behaving proxies. 13 | For more information about the importance of good masking, 14 | see \l {"Talking to Yourself for Fun and Profit" by Lin-Shung Huang et al}. 15 | The default mask generator uses the reasonably secure QRandomGenerator::global()->generate() function. 16 | The best measure against attacks mentioned in the document above, 17 | is to use QWebSocket over a secure connection (\e wss://). 18 | In general, always be careful to not have 3rd party script access to 19 | a QWebSocket in your application. 20 | 21 | \internal 22 | */ 23 | 24 | #include "qdefaultmaskgenerator_p.h" 25 | #include 26 | 27 | QT_BEGIN_NAMESPACE 28 | 29 | /*! 30 | Constructs a new QDefaultMaskGenerator with the given \a parent. 31 | 32 | \internal 33 | */ 34 | QDefaultMaskGenerator::QDefaultMaskGenerator(QObject *parent) : 35 | QMaskGenerator(parent) 36 | { 37 | } 38 | 39 | /*! 40 | Destroys the QDefaultMaskGenerator object. 41 | 42 | \internal 43 | */ 44 | QDefaultMaskGenerator::~QDefaultMaskGenerator() 45 | { 46 | } 47 | 48 | /*! 49 | \internal 50 | */ 51 | bool QDefaultMaskGenerator::seed() noexcept 52 | { 53 | return true; 54 | } 55 | 56 | /*! 57 | Generates a new random mask using the insecure QRandomGenerator::global()->generate() method. 58 | 59 | \internal 60 | */ 61 | quint32 QDefaultMaskGenerator::nextMask() noexcept 62 | { 63 | quint32 value = QRandomGenerator::global()->generate(); 64 | while (Q_UNLIKELY(value == 0)) { 65 | // a mask of zero has a special meaning 66 | value = QRandomGenerator::global()->generate(); 67 | } 68 | return value; 69 | } 70 | 71 | QT_END_NAMESPACE 72 | -------------------------------------------------------------------------------- /src/websockets/qdefaultmaskgenerator_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #ifndef QDEFAULTMASKGENERATOR_P_H 5 | #define QDEFAULTMASKGENERATOR_P_H 6 | 7 | // 8 | // W A R N I N G 9 | // ------------- 10 | // 11 | // This file is not part of the Qt API. It exists purely as an 12 | // implementation detail. This header file may change from version to 13 | // version without notice, or even be removed. 14 | // 15 | // We mean it. 16 | // 17 | 18 | #include 19 | #include 20 | 21 | QT_BEGIN_NAMESPACE 22 | class QObject; 23 | 24 | class Q_AUTOTEST_EXPORT QDefaultMaskGenerator : public QMaskGenerator 25 | { 26 | Q_DISABLE_COPY(QDefaultMaskGenerator) 27 | 28 | public: 29 | explicit QDefaultMaskGenerator(QObject *parent = nullptr); 30 | ~QDefaultMaskGenerator() override; 31 | 32 | bool seed() noexcept override; 33 | quint32 nextMask() noexcept override; 34 | }; 35 | 36 | QT_END_NAMESPACE 37 | 38 | #endif // QDEFAULTMASKGENERATOR_P_H 39 | -------------------------------------------------------------------------------- /src/websockets/qmaskgenerator.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | /*! 5 | \class QMaskGenerator 6 | 7 | \inmodule QtWebSockets 8 | \since 5.3 9 | 10 | \brief The QMaskGenerator class provides an abstract base for custom 32-bit mask generators. 11 | 12 | The WebSockets specification as outlined in \l {RFC 6455} 13 | requires that all communication from client to server be masked. This is to prevent 14 | malicious scripts from attacking badly behaving proxies. 15 | For more information about the importance of good masking, 16 | see \l {"Talking to Yourself for Fun and Profit" by Lin-Shung Huang et al}. 17 | By default QWebSocket uses the reasonably secure QRandomGenerator::global()->generate() function. 18 | The best measure against attacks mentioned in the document above, 19 | is to use QWebSocket over a secure connection (\e wss://). 20 | In general, always be careful to not have 3rd party script access to 21 | a QWebSocket in your application. 22 | */ 23 | 24 | /*! 25 | \fn bool QMaskGenerator::seed() 26 | 27 | Initializes the QMaskGenerator by seeding the randomizer. 28 | When seed() is not called, it depends on the specific implementation of a subclass if 29 | a default seed is used or no seed is used at all. 30 | Returns \e true if seeding succeeds, otherwise false. 31 | */ 32 | 33 | /*! 34 | \fn quint32 QMaskGenerator::nextMask() 35 | 36 | Returns a new random 32-bit mask. The randomness depends on the RNG used to created the 37 | mask. 38 | */ 39 | 40 | #include "qmaskgenerator.h" 41 | 42 | QT_BEGIN_NAMESPACE 43 | 44 | /*! 45 | Creates a new QMaskGenerator object with the given optional QObject \a parent. 46 | */ 47 | QMaskGenerator::QMaskGenerator(QObject *parent) : 48 | QObject(parent) 49 | { 50 | } 51 | 52 | /*! 53 | Destroys the QMaskGenerator object. 54 | */ 55 | QMaskGenerator::~QMaskGenerator() 56 | {} 57 | 58 | QT_END_NAMESPACE 59 | -------------------------------------------------------------------------------- /src/websockets/qmaskgenerator.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #ifndef QMASKGENERATOR_H 5 | #define QMASKGENERATOR_H 6 | 7 | #include 8 | #include "QtWebSockets/qwebsockets_global.h" 9 | 10 | QT_BEGIN_NAMESPACE 11 | 12 | class Q_WEBSOCKETS_EXPORT QMaskGenerator : public QObject 13 | { 14 | Q_DISABLE_COPY(QMaskGenerator) 15 | 16 | public: 17 | explicit QMaskGenerator(QObject *parent = nullptr); 18 | ~QMaskGenerator() override; 19 | 20 | virtual bool seed() = 0; 21 | virtual quint32 nextMask() = 0; 22 | }; 23 | 24 | QT_END_NAMESPACE 25 | 26 | #endif // QMASKGENERATOR_H 27 | -------------------------------------------------------------------------------- /src/websockets/qwebsocketcorsauthenticator.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | #ifndef QWEBSOCKETCORSAUTHENTICATOR_H 4 | #define QWEBSOCKETCORSAUTHENTICATOR_H 5 | 6 | #include "QtWebSockets/qwebsockets_global.h" 7 | #include 8 | 9 | QT_BEGIN_NAMESPACE 10 | 11 | class QWebSocketCorsAuthenticatorPrivate; 12 | 13 | class Q_WEBSOCKETS_EXPORT QWebSocketCorsAuthenticator 14 | { 15 | Q_DECLARE_PRIVATE(QWebSocketCorsAuthenticator) 16 | 17 | public: 18 | explicit QWebSocketCorsAuthenticator(const QString &origin); 19 | ~QWebSocketCorsAuthenticator(); 20 | explicit QWebSocketCorsAuthenticator(const QWebSocketCorsAuthenticator &other); 21 | 22 | QWebSocketCorsAuthenticator(QWebSocketCorsAuthenticator &&other) noexcept; 23 | QWebSocketCorsAuthenticator &operator =(QWebSocketCorsAuthenticator &&other) noexcept; 24 | 25 | void swap(QWebSocketCorsAuthenticator &other) noexcept; 26 | 27 | QWebSocketCorsAuthenticator &operator =(const QWebSocketCorsAuthenticator &other); 28 | 29 | QString origin() const; 30 | 31 | void setAllowed(bool allowed); 32 | bool allowed() const; 33 | 34 | private: 35 | std::unique_ptr d_ptr; 36 | }; 37 | 38 | QT_END_NAMESPACE 39 | 40 | #endif // QWEBSOCKETCORSAUTHENTICATOR_H 41 | -------------------------------------------------------------------------------- /src/websockets/qwebsocketcorsauthenticator_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | #ifndef QWEBSOCKETCORSAUTHENTICATOR_P_H 4 | #define QWEBSOCKETCORSAUTHENTICATOR_P_H 5 | 6 | #include 7 | #include 8 | 9 | // 10 | // W A R N I N G 11 | // ------------- 12 | // 13 | // This file is not part of the Qt API. It exists purely as an 14 | // implementation detail. This header file may change from version to 15 | // version without notice, or even be removed. 16 | // 17 | // We mean it. 18 | // 19 | QT_BEGIN_NAMESPACE 20 | 21 | class QWebSocketCorsAuthenticatorPrivate 22 | { 23 | public: 24 | QWebSocketCorsAuthenticatorPrivate(const QString &origin, bool allowed); 25 | ~QWebSocketCorsAuthenticatorPrivate(); 26 | 27 | QString m_origin; 28 | bool m_isAllowed; 29 | }; 30 | 31 | QT_END_NAMESPACE 32 | 33 | #endif // QWEBSOCKETCORSAUTHENTICATOR_P_H 34 | -------------------------------------------------------------------------------- /src/websockets/qwebsocketdataprocessor_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #ifndef QWEBSOCKETDATAPROCESSOR_P_H 5 | #define QWEBSOCKETDATAPROCESSOR_P_H 6 | 7 | // 8 | // W A R N I N G 9 | // ------------- 10 | // 11 | // This file is not part of the Qt API. It exists purely as an 12 | // implementation detail. This header file may change from version to 13 | // version without notice, or even be removed. 14 | // 15 | // We mean it. 16 | // 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "qwebsocketframe_p.h" 24 | #include "qwebsocketprotocol.h" 25 | #include "qwebsocketprotocol_p.h" 26 | 27 | QT_BEGIN_NAMESPACE 28 | 29 | class QIODevice; 30 | class QWebSocketFrame; 31 | 32 | const quint64 MAX_MESSAGE_SIZE_IN_BYTES = std::numeric_limits::max() - 1; 33 | 34 | class Q_AUTOTEST_EXPORT QWebSocketDataProcessor : public QObject 35 | { 36 | Q_OBJECT 37 | Q_DISABLE_COPY(QWebSocketDataProcessor) 38 | 39 | public: 40 | explicit QWebSocketDataProcessor(QObject *parent = nullptr); 41 | ~QWebSocketDataProcessor() override; 42 | 43 | void setMaxAllowedFrameSize(quint64 maxAllowedFrameSize); 44 | quint64 maxAllowedFrameSize() const; 45 | void setMaxAllowedMessageSize(quint64 maxAllowedMessageSize); 46 | quint64 maxAllowedMessageSize() const; 47 | static quint64 maxMessageSize(); 48 | static quint64 maxFrameSize(); 49 | 50 | void setIdleTimeout(std::chrono::milliseconds timeout); 51 | std::chrono::milliseconds idleTimeout() const; 52 | 53 | Q_SIGNALS: 54 | void pingReceived(const QByteArray &data); 55 | void pongReceived(const QByteArray &data); 56 | void closeReceived(QWebSocketProtocol::CloseCode closeCode, const QString &closeReason); 57 | void textFrameReceived(const QString &frame, bool lastFrame); 58 | void binaryFrameReceived(const QByteArray &frame, bool lastFrame); 59 | void textMessageReceived(const QString &message); 60 | void binaryMessageReceived(const QByteArray &message); 61 | void errorEncountered(QWebSocketProtocol::CloseCode code, const QString &description); 62 | 63 | public Q_SLOTS: 64 | bool process(QIODevice *pIoDevice); 65 | void clear(); 66 | 67 | private: 68 | enum 69 | { 70 | PS_READ_HEADER, 71 | PS_READ_PAYLOAD_LENGTH, 72 | PS_READ_BIG_PAYLOAD_LENGTH, 73 | PS_READ_MASK, 74 | PS_READ_PAYLOAD, 75 | PS_DISPATCH_RESULT 76 | } m_processingState; 77 | 78 | bool m_isFinalFrame; 79 | bool m_isFragmented; 80 | QWebSocketProtocol::OpCode m_opCode; 81 | bool m_isControlFrame; 82 | bool m_hasMask; 83 | quint32 m_mask; 84 | QByteArray m_binaryMessage; 85 | QString m_textMessage; 86 | quint64 m_payloadLength; 87 | QStringDecoder m_decoder; 88 | QWebSocketFrame frame; 89 | QChronoTimer *m_waitTimer; 90 | quint64 m_maxAllowedMessageSize = MAX_MESSAGE_SIZE_IN_BYTES; 91 | 92 | bool processControlFrame(const QWebSocketFrame &frame); 93 | void timeout(); 94 | }; 95 | 96 | QT_END_NAMESPACE 97 | 98 | #endif // QWEBSOCKETDATAPROCESSOR_P_H 99 | -------------------------------------------------------------------------------- /src/websockets/qwebsocketframe_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #ifndef QWEBSOCKETFRAME_P_H 5 | #define QWEBSOCKETFRAME_P_H 6 | 7 | // 8 | // W A R N I N G 9 | // ------------- 10 | // 11 | // This file is not part of the Qt API. It exists purely as an 12 | // implementation detail. This header file may change from version to 13 | // version without notice, or even be removed. 14 | // 15 | // We mean it. 16 | // 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "qwebsockets_global.h" 24 | #include "qwebsocketprotocol.h" 25 | #include "qwebsocketprotocol_p.h" 26 | 27 | QT_BEGIN_NAMESPACE 28 | 29 | class QIODevice; 30 | 31 | const quint64 MAX_FRAME_SIZE_IN_BYTES = std::numeric_limits::max() - 1; 32 | 33 | class Q_AUTOTEST_EXPORT QWebSocketFrame 34 | { 35 | Q_DECLARE_TR_FUNCTIONS(QWebSocketFrame) 36 | 37 | public: 38 | QWebSocketFrame() = default; 39 | 40 | void setMaxAllowedFrameSize(quint64 maxAllowedFrameSize); 41 | quint64 maxAllowedFrameSize() const; 42 | static quint64 maxFrameSize(); 43 | 44 | QWebSocketProtocol::CloseCode closeCode() const; 45 | QString closeReason() const; 46 | bool isFinalFrame() const; 47 | bool isControlFrame() const; 48 | bool isDataFrame() const; 49 | bool isContinuationFrame() const; 50 | bool hasMask() const; 51 | quint32 mask() const; //returns 0 if no mask 52 | inline bool rsv1() const { return m_rsv1; } 53 | inline bool rsv2() const { return m_rsv2; } 54 | inline bool rsv3() const { return m_rsv3; } 55 | QWebSocketProtocol::OpCode opCode() const; 56 | QByteArray payload() const; 57 | 58 | void clear(); 59 | 60 | bool isValid() const; 61 | bool isDone() const; 62 | 63 | void readFrame(QIODevice *pIoDevice); 64 | 65 | private: 66 | QString m_closeReason; 67 | QByteArray m_payload; 68 | quint64 m_length = 0; 69 | quint32 m_mask = 0; 70 | QWebSocketProtocol::CloseCode m_closeCode = QWebSocketProtocol::CloseCodeNormal; 71 | QWebSocketProtocol::OpCode m_opCode = QWebSocketProtocol::OpCodeReservedC; 72 | 73 | enum ProcessingState 74 | { 75 | PS_READ_HEADER, 76 | PS_READ_PAYLOAD_LENGTH, 77 | PS_READ_MASK, 78 | PS_READ_PAYLOAD, 79 | PS_DISPATCH_RESULT, 80 | PS_WAIT_FOR_MORE_DATA 81 | } m_processingState = PS_READ_HEADER; 82 | 83 | bool m_isFinalFrame = true; 84 | bool m_rsv1 = false; 85 | bool m_rsv2 = false; 86 | bool m_rsv3 = false; 87 | bool m_isValid = false; 88 | quint64 m_maxAllowedFrameSize = MAX_FRAME_SIZE_IN_BYTES; 89 | 90 | ProcessingState readFrameHeader(QIODevice *pIoDevice); 91 | ProcessingState readFramePayloadLength(QIODevice *pIoDevice); 92 | ProcessingState readFrameMask(QIODevice *pIoDevice); 93 | ProcessingState readFramePayload(QIODevice *pIoDevice); 94 | 95 | void setError(QWebSocketProtocol::CloseCode code, const QString &closeReason); 96 | bool checkValidity(); 97 | }; 98 | 99 | QT_END_NAMESPACE 100 | 101 | #endif // QWEBSOCKETFRAME_P_H 102 | -------------------------------------------------------------------------------- /src/websockets/qwebsockethandshakeoptions.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2022 Menlo Systems GmbH, author Arno Rehn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #include "qwebsockethandshakeoptions_p.h" 5 | 6 | QT_BEGIN_NAMESPACE 7 | 8 | /*! 9 | \class QWebSocketHandshakeOptions 10 | 11 | \inmodule QtWebSockets 12 | \since 6.4 13 | \brief Collects options for the WebSocket handshake. 14 | 15 | QWebSocketHandshakeOptions collects options that are passed along to the 16 | WebSocket handshake, such as WebSocket subprotocols and WebSocket 17 | Extensions. 18 | 19 | At the moment, only WebSocket subprotocols are supported. 20 | 21 | \sa QWebSocket::open() 22 | */ 23 | 24 | /*! 25 | \brief Constructs an empty QWebSocketHandshakeOptions object. 26 | */ 27 | QWebSocketHandshakeOptions::QWebSocketHandshakeOptions() 28 | : d(new QWebSocketHandshakeOptionsPrivate) 29 | { 30 | } 31 | 32 | /*! 33 | \brief Constructs a QWebSocketHandshakeOptions that is a copy of \a other. 34 | */ 35 | QWebSocketHandshakeOptions::QWebSocketHandshakeOptions(const QWebSocketHandshakeOptions &other) 36 | : d(other.d) 37 | { 38 | } 39 | 40 | /*! 41 | \fn QWebSocketHandshakeOptions::QWebSocketHandshakeOptions(QWebSocketHandshakeOptions &&other) noexcept 42 | \brief Constructs a QWebSocketHandshakeOptions that is moved from \a other. 43 | */ 44 | 45 | /*! 46 | \brief Destroys this object. 47 | */ 48 | QWebSocketHandshakeOptions::~QWebSocketHandshakeOptions() 49 | { 50 | } 51 | 52 | /*! 53 | \fn QWebSocketHandshakeOptions &QWebSocketHandshakeOptions::operator=(QWebSocketHandshakeOptions &&other) noexcept 54 | \brief Moves \a other to this object. 55 | */ 56 | 57 | /*! 58 | \brief Assigns \a other to this object. 59 | */ 60 | QWebSocketHandshakeOptions &QWebSocketHandshakeOptions::operator=( 61 | const QWebSocketHandshakeOptions &other) 62 | { 63 | d = other.d; 64 | return *this; 65 | } 66 | 67 | /*! 68 | \fn void swap(QWebSocketHandshakeOptions &other) noexcept 69 | \brief Swaps this object with \a other. 70 | */ 71 | 72 | /*! 73 | \brief Returns the list of WebSocket subprotocols to send along with the 74 | websocket handshake. 75 | */ 76 | QStringList QWebSocketHandshakeOptions::subprotocols() const 77 | { 78 | return d->subprotocols; 79 | } 80 | 81 | /*! 82 | \brief Sets the list of WebSocket subprotocols \a protocols to send along 83 | with the websocket handshake. 84 | 85 | WebSocket subprotocol names may only consist of those US-ASCII characters 86 | that are in the unreserved group. Invalid protocol names will not be 87 | included in the handshake. 88 | */ 89 | void QWebSocketHandshakeOptions::setSubprotocols(const QStringList &protocols) 90 | { 91 | d->subprotocols = protocols; 92 | } 93 | 94 | bool QWebSocketHandshakeOptions::equals(const QWebSocketHandshakeOptions &other) const 95 | { 96 | return *d == *other.d; 97 | } 98 | 99 | /*! 100 | //! friend 101 | \fn QWebSocketHandshakeOptions::operator==(const QWebSocketHandshakeOptions &lhs, const QWebSocketHandshakeOptions &rhs) 102 | \fn QWebSocketHandshakeOptions::operator!=(const QWebSocketHandshakeOptions &lhs, const QWebSocketHandshakeOptions &rhs) 103 | \brief Compares \a lhs for equality with \a rhs. 104 | */ 105 | 106 | QT_DEFINE_QSDP_SPECIALIZATION_DTOR(QWebSocketHandshakeOptionsPrivate) 107 | 108 | QT_END_NAMESPACE 109 | -------------------------------------------------------------------------------- /src/websockets/qwebsockethandshakeoptions.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2022 Menlo Systems GmbH, author Arno Rehn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | 5 | #ifndef QWEBSOCKETHANDSHAKEOPTIONS_H 6 | #define QWEBSOCKETHANDSHAKEOPTIONS_H 7 | 8 | #include 9 | #include 10 | 11 | #include "QtWebSockets/qwebsockets_global.h" 12 | 13 | QT_BEGIN_NAMESPACE 14 | 15 | class QWebSocketHandshakeOptionsPrivate; 16 | 17 | QT_DECLARE_QSDP_SPECIALIZATION_DTOR_WITH_EXPORT(QWebSocketHandshakeOptionsPrivate, Q_WEBSOCKETS_EXPORT) 18 | 19 | class Q_WEBSOCKETS_EXPORT QWebSocketHandshakeOptions 20 | { 21 | public: 22 | QWebSocketHandshakeOptions(); 23 | QWebSocketHandshakeOptions(const QWebSocketHandshakeOptions &other); 24 | QWebSocketHandshakeOptions(QWebSocketHandshakeOptions &&other) noexcept = default; 25 | ~QWebSocketHandshakeOptions(); 26 | 27 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QWebSocketHandshakeOptions) 28 | QWebSocketHandshakeOptions &operator=(const QWebSocketHandshakeOptions &other); 29 | 30 | void swap(QWebSocketHandshakeOptions &other) noexcept { d.swap(other.d); } 31 | 32 | QStringList subprotocols() const; 33 | void setSubprotocols(const QStringList &protocols); 34 | 35 | private: 36 | bool equals(const QWebSocketHandshakeOptions &other) const; 37 | 38 | friend bool operator==(const QWebSocketHandshakeOptions &lhs, 39 | const QWebSocketHandshakeOptions &rhs) { return lhs.equals(rhs); } 40 | friend bool operator!=(const QWebSocketHandshakeOptions &lhs, 41 | const QWebSocketHandshakeOptions &rhs) { return !lhs.equals(rhs); } 42 | 43 | QSharedDataPointer d; 44 | friend class QWebSocketHandshakeOptionsPrivate; 45 | }; 46 | 47 | QT_END_NAMESPACE 48 | 49 | #endif // QWEBSOCKETHANDSHAKEOPTIONS_H 50 | -------------------------------------------------------------------------------- /src/websockets/qwebsockethandshakeoptions_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2022 Menlo Systems GmbH, author Arno Rehn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #ifndef QWEBSOCKETHANDSHAKEOPTIONS_P_H 5 | #define QWEBSOCKETHANDSHAKEOPTIONS_P_H 6 | 7 | // 8 | // W A R N I N G 9 | // ------------- 10 | // 11 | // This file is not part of the Qt API. It exists purely as an 12 | // implementation detail. This header file may change from version to 13 | // version without notice, or even be removed. 14 | // 15 | // We mean it. 16 | // 17 | 18 | #include 19 | 20 | #include "qwebsockethandshakeoptions.h" 21 | 22 | QT_BEGIN_NAMESPACE 23 | 24 | class Q_AUTOTEST_EXPORT QWebSocketHandshakeOptionsPrivate : public QSharedData 25 | { 26 | public: 27 | inline bool operator==(const QWebSocketHandshakeOptionsPrivate &other) const 28 | { return subprotocols == other.subprotocols; } 29 | 30 | QStringList subprotocols; 31 | }; 32 | 33 | QT_END_NAMESPACE 34 | 35 | #endif // QWEBSOCKETHANDSHAKEOPTIONS_P_H 36 | -------------------------------------------------------------------------------- /src/websockets/qwebsockethandshakerequest_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #ifndef QWEBSOCKETHANDSHAKEREQUEST_P_H 5 | #define QWEBSOCKETHANDSHAKEREQUEST_P_H 6 | // 7 | // W A R N I N G 8 | // ------------- 9 | // 10 | // This file is not part of the Qt API. It exists purely as an 11 | // implementation detail. This header file may change from version to 12 | // version without notice, or even be removed. 13 | // 14 | // We mean it. 15 | // 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "qwebsocketprotocol.h" 25 | 26 | QT_BEGIN_NAMESPACE 27 | 28 | class QTextStream; 29 | 30 | class Q_AUTOTEST_EXPORT QWebSocketHandshakeRequest 31 | { 32 | Q_DISABLE_COPY(QWebSocketHandshakeRequest) 33 | 34 | public: 35 | QWebSocketHandshakeRequest(int port, bool isSecure); 36 | virtual ~QWebSocketHandshakeRequest(); 37 | 38 | void clear(); 39 | 40 | int port() const; 41 | bool isSecure() const; 42 | bool isValid() const; 43 | QHttpHeaders headers() const; 44 | bool hasHeader(const QByteArray &name) const; 45 | QList versions() const; 46 | QString key() const; 47 | QString origin() const; 48 | QList protocols() const; 49 | QList extensions() const; 50 | QUrl requestUrl() const; 51 | QString resourceName() const; 52 | QString host() const; 53 | 54 | void readHandshake(QByteArrayView header, int maxHeaderLineLength); 55 | 56 | private: 57 | 58 | int m_port; 59 | bool m_isSecure; 60 | bool m_isValid; 61 | QHttpHeaderParser m_parser; 62 | QList m_versions; 63 | QString m_key; 64 | QString m_origin; 65 | QList m_protocols; 66 | QList m_extensions; 67 | QUrl m_requestUrl; 68 | }; 69 | 70 | QT_END_NAMESPACE 71 | 72 | #endif // QWEBSOCKETHANDSHAKEREQUEST_P_H 73 | -------------------------------------------------------------------------------- /src/websockets/qwebsockethandshakeresponse_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #ifndef QWEBSOCKETHANDSHAKERESPONSE_P_H 5 | #define QWEBSOCKETHANDSHAKERESPONSE_P_H 6 | // 7 | // W A R N I N G 8 | // ------------- 9 | // 10 | // This file is not part of the Qt API. It exists purely as an 11 | // implementation detail. This header file may change from version to 12 | // version without notice, or even be removed. 13 | // 14 | // We mean it. 15 | // 16 | 17 | #include 18 | #include 19 | #include "qwebsocketprotocol.h" 20 | #include "private/qglobal_p.h" 21 | 22 | QT_BEGIN_NAMESPACE 23 | 24 | class QWebSocketHandshakeRequest; 25 | class QString; 26 | class QTextStream; 27 | 28 | class Q_AUTOTEST_EXPORT QWebSocketHandshakeResponse : public QObject 29 | { 30 | Q_OBJECT 31 | Q_DISABLE_COPY(QWebSocketHandshakeResponse) 32 | 33 | public: 34 | QWebSocketHandshakeResponse(const QWebSocketHandshakeRequest &request, 35 | const QString &serverName, 36 | bool isOriginAllowed, 37 | const QList &supportedVersions, 38 | const QList &supportedProtocols, 39 | const QList &supportedExtensions); 40 | 41 | ~QWebSocketHandshakeResponse() override; 42 | 43 | bool isValid() const; 44 | bool canUpgrade() const; 45 | QString acceptedProtocol() const; 46 | QString acceptedExtension() const; 47 | QWebSocketProtocol::Version acceptedVersion() const; 48 | 49 | QWebSocketProtocol::CloseCode error() const; 50 | QString errorString() const; 51 | 52 | private: 53 | bool m_isValid; 54 | bool m_canUpgrade; 55 | QString m_response; 56 | QString m_acceptedProtocol; 57 | QString m_acceptedExtension; 58 | QWebSocketProtocol::Version m_acceptedVersion; 59 | QWebSocketProtocol::CloseCode m_error; 60 | QString m_errorString; 61 | 62 | QString calculateAcceptKey(const QString &key) const; 63 | QString getHandshakeResponse(const QWebSocketHandshakeRequest &request, 64 | const QString &serverName, 65 | bool isOriginAllowed, 66 | const QList &supportedVersions, 67 | const QList &supportedProtocols, 68 | const QList &supportedExtensions); 69 | 70 | QTextStream &writeToStream(QTextStream &textStream) const; 71 | Q_AUTOTEST_EXPORT friend QTextStream & operator <<(QTextStream &stream, 72 | const QWebSocketHandshakeResponse &response); 73 | }; 74 | 75 | Q_AUTOTEST_EXPORT QTextStream & operator <<(QTextStream &stream, 76 | const QWebSocketHandshakeResponse &response); 77 | 78 | QT_END_NAMESPACE 79 | 80 | #endif // QWEBSOCKETHANDSHAKERESPONSE_P_H 81 | -------------------------------------------------------------------------------- /src/websockets/qwebsocketprotocol.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #ifndef QWEBSOCKETPROTOCOL_H 5 | #define QWEBSOCKETPROTOCOL_H 6 | 7 | #if 0 8 | # pragma qt_class(QWebSocketProtocol) 9 | #endif 10 | 11 | #include 12 | #include "QtWebSockets/qwebsockets_global.h" 13 | 14 | QT_BEGIN_NAMESPACE 15 | 16 | class QString; 17 | 18 | namespace QWebSocketProtocol 19 | { 20 | enum Version 21 | { 22 | VersionUnknown = -1, 23 | Version0 = 0, 24 | //hybi-01, hybi-02 and hybi-03 not supported 25 | Version4 = 4, 26 | Version5 = 5, 27 | Version6 = 6, 28 | Version7 = 7, 29 | Version8 = 8, 30 | Version13 = 13, 31 | VersionLatest = Version13 32 | }; 33 | 34 | enum CloseCode 35 | { 36 | CloseCodeNormal = 1000, 37 | CloseCodeGoingAway = 1001, 38 | CloseCodeProtocolError = 1002, 39 | CloseCodeDatatypeNotSupported = 1003, 40 | CloseCodeReserved1004 = 1004, 41 | CloseCodeMissingStatusCode = 1005, 42 | CloseCodeAbnormalDisconnection = 1006, 43 | CloseCodeWrongDatatype = 1007, 44 | CloseCodePolicyViolated = 1008, 45 | CloseCodeTooMuchData = 1009, 46 | CloseCodeMissingExtension = 1010, 47 | CloseCodeBadOperation = 1011, 48 | CloseCodeTlsHandshakeFailed = 1015 49 | }; 50 | 51 | } //end namespace QWebSocketProtocol 52 | 53 | QT_END_NAMESPACE 54 | 55 | #endif // QWEBSOCKETPROTOCOL_H 56 | -------------------------------------------------------------------------------- /src/websockets/qwebsocketprotocol_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #ifndef QWEBSOCKETPROTOCOL_P_H 5 | #define QWEBSOCKETPROTOCOL_P_H 6 | 7 | // 8 | // W A R N I N G 9 | // ------------- 10 | // 11 | // This file is not part of the Qt API. It exists purely as an 12 | // implementation detail. This header file may change from version to 13 | // version without notice, or even be removed. 14 | // 15 | // We mean it. 16 | // 17 | 18 | #include 19 | #include "QtWebSockets/qwebsocketprotocol.h" 20 | 21 | #include 22 | 23 | QT_BEGIN_NAMESPACE 24 | 25 | class QByteArray; 26 | 27 | namespace QWebSocketProtocol 28 | { 29 | enum OpCode 30 | { 31 | OpCodeContinue = 0x0, 32 | OpCodeText = 0x1, 33 | OpCodeBinary = 0x2, 34 | OpCodeReserved3 = 0x3, 35 | OpCodeReserved4 = 0x4, 36 | OpCodeReserved5 = 0x5, 37 | OpCodeReserved6 = 0x6, 38 | OpCodeReserved7 = 0x7, 39 | OpCodeClose = 0x8, 40 | OpCodePing = 0x9, 41 | OpCodePong = 0xA, 42 | OpCodeReservedB = 0xB, 43 | OpCodeReservedC = 0xC, 44 | OpCodeReservedD = 0xD, 45 | OpCodeReservedE = 0xE, 46 | OpCodeReservedF = 0xF 47 | }; 48 | 49 | inline bool isOpCodeReserved(OpCode code) 50 | { 51 | return ((code > OpCodeBinary) && (code < OpCodeClose)) || (code > OpCodePong); 52 | } 53 | 54 | inline bool isCloseCodeValid(int closeCode) 55 | { 56 | return (closeCode > 999) && (closeCode < 5000) && 57 | (closeCode != CloseCodeReserved1004) && //see RFC6455 7.4.1 58 | (closeCode != CloseCodeMissingStatusCode) && 59 | (closeCode != CloseCodeAbnormalDisconnection) && 60 | ((closeCode >= 3000) || (closeCode < 1012)); 61 | } 62 | 63 | inline Version currentVersion() { return VersionLatest; } 64 | Version Q_AUTOTEST_EXPORT versionFromString(QStringView versionString); 65 | 66 | void Q_AUTOTEST_EXPORT mask(QByteArray *payload, quint32 maskingKey); 67 | void Q_AUTOTEST_EXPORT mask(char *payload, quint64 size, quint32 maskingKey); 68 | } //end namespace QWebSocketProtocol 69 | 70 | QT_END_NAMESPACE 71 | 72 | #endif // QWEBSOCKETPROTOCOL_P_H 73 | -------------------------------------------------------------------------------- /src/websockets/qwebsockets_global.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #ifndef QWEBSOCKETSGLOBAL_H 5 | #define QWEBSOCKETSGLOBAL_H 6 | 7 | #include 8 | #include 9 | 10 | #endif // QWEBSOCKETSGLOBAL_H 11 | -------------------------------------------------------------------------------- /src/websockets/qwebsocketserver_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | 4 | #ifndef QWEBSOCKETSERVER_P_H 5 | #define QWEBSOCKETSERVER_P_H 6 | // 7 | // W A R N I N G 8 | // ------------- 9 | // 10 | // This file is not part of the Qt API. It exists purely as an 11 | // implementation detail. This header file may change from version to 12 | // version without notice, or even be removed. 13 | // 14 | // We mean it. 15 | // 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "qwebsocketserver.h" 23 | #include "qwebsocket.h" 24 | 25 | #ifndef QT_NO_SSL 26 | #include 27 | #include 28 | #endif 29 | 30 | QT_BEGIN_NAMESPACE 31 | 32 | class QTcpServer; 33 | class QTcpSocket; 34 | 35 | class QWebSocketServerPrivate : public QObjectPrivate 36 | { 37 | Q_DISABLE_COPY(QWebSocketServerPrivate) 38 | 39 | public: 40 | Q_DECLARE_PUBLIC(QWebSocketServer) 41 | enum SslMode 42 | { 43 | SecureMode = true, 44 | NonSecureMode 45 | }; 46 | 47 | explicit QWebSocketServerPrivate(const QString &serverName, SslMode secureMode); 48 | ~QWebSocketServerPrivate() override; 49 | 50 | void init(); 51 | void close(bool aboutToDestroy = false); 52 | QString errorString() const; 53 | bool hasPendingConnections() const; 54 | bool isListening() const; 55 | bool listen(const QHostAddress &address = QHostAddress::Any, quint16 port = 0); 56 | int maxPendingConnections() const; 57 | int handshakeTimeout() const { 58 | return m_handshakeTimeout; 59 | } 60 | virtual QWebSocket *nextPendingConnection(); 61 | void pauseAccepting(); 62 | #ifndef QT_NO_NETWORKPROXY 63 | QNetworkProxy proxy() const; 64 | void setProxy(const QNetworkProxy &networkProxy); 65 | #endif 66 | void resumeAccepting(); 67 | QHostAddress serverAddress() const; 68 | QWebSocketProtocol::CloseCode serverError() const; 69 | quint16 serverPort() const; 70 | void setMaxPendingConnections(int numConnections); 71 | void setHandshakeTimeout(int msec); 72 | bool setSocketDescriptor(qintptr socketDescriptor); 73 | qintptr socketDescriptor() const; 74 | 75 | QList supportedVersions() const; 76 | void setSupportedSubprotocols(const QStringList &protocols); 77 | QStringList supportedSubprotocols() const; 78 | QStringList supportedExtensions() const; 79 | 80 | void setServerName(const QString &serverName); 81 | QString serverName() const; 82 | 83 | SslMode secureMode() const; 84 | 85 | #ifndef QT_NO_SSL 86 | void setSslConfiguration(const QSslConfiguration &sslConfiguration); 87 | QSslConfiguration sslConfiguration() const; 88 | #endif 89 | 90 | void setError(QWebSocketProtocol::CloseCode code, const QString &errorString); 91 | 92 | void handleConnection(QTcpSocket *pTcpSocket) const; 93 | 94 | private slots: 95 | void startHandshakeTimeout(QTcpSocket *pTcpSocket); 96 | 97 | private: 98 | QTcpServer *m_pTcpServer; 99 | QString m_serverName; 100 | SslMode m_secureMode; 101 | QStringList m_supportedSubprotocols; 102 | QQueue m_pendingConnections; 103 | QWebSocketProtocol::CloseCode m_error; 104 | QString m_errorString; 105 | int m_maxPendingConnections; 106 | int m_handshakeTimeout; 107 | 108 | void addPendingConnection(QWebSocket *pWebSocket); 109 | void setErrorFromSocketError(QAbstractSocket::SocketError error, 110 | const QString &errorDescription); 111 | 112 | void onNewConnection(); 113 | void onSocketDisconnected(); 114 | void handshakeReceived(); 115 | void finishHandshakeTimeout(QTcpSocket *pTcpSocket); 116 | }; 117 | 118 | QT_END_NAMESPACE 119 | 120 | #endif // QWEBSOCKETSERVER_P_H 121 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from tests.pro. 5 | 6 | if(QT_BUILD_STANDALONE_TESTS) 7 | # Add qt_find_package calls for extra dependencies that need to be found when building 8 | # the standalone tests here. 9 | endif() 10 | 11 | qt_build_tests() 12 | 13 | -------------------------------------------------------------------------------- /tests/auto/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | add_subdirectory(cmake) 5 | add_subdirectory(websockets) 6 | if(TARGET Qt::Quick) 7 | add_subdirectory(qml) 8 | endif() 9 | -------------------------------------------------------------------------------- /tests/auto/cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # This is an automatic test for the CMake configuration files. 5 | # To run it manually, 6 | # 1) mkdir build # Create a build directory 7 | # 2) cd build 8 | # 3) # Run cmake on this directory 9 | # `$qt_prefix/bin/qt-cmake ..` or `cmake -DCMAKE_PREFIX_PATH=/path/to/qt ..` 10 | # 4) ctest # Run ctest 11 | 12 | cmake_minimum_required(VERSION 3.16) 13 | project(websockets_cmake_tests) 14 | enable_testing() 15 | 16 | set(required_packages Core WebSockets) 17 | 18 | # Setup the test when called as a completely standalone project. 19 | if(TARGET Qt6::Core) 20 | # Tests are built as part of the repository's build tree. 21 | # Setup paths so that the Qt packages are found. 22 | qt_internal_set_up_build_dir_package_paths() 23 | endif() 24 | 25 | find_package(Qt6 REQUIRED COMPONENTS ${required_packages}) 26 | 27 | # Setup common test variables which were previously set by ctest_testcase_common.prf. 28 | set(CMAKE_MODULES_UNDER_TEST "${required_packages}") 29 | 30 | foreach(qt_package ${CMAKE_MODULES_UNDER_TEST}) 31 | set(package_name "${QT_CMAKE_EXPORT_NAMESPACE}${qt_package}") 32 | if(${package_name}_FOUND) 33 | set(CMAKE_${qt_package}_MODULE_MAJOR_VERSION "${${package_name}_VERSION_MAJOR}") 34 | set(CMAKE_${qt_package}_MODULE_MINOR_VERSION "${${package_name}_VERSION_MINOR}") 35 | set(CMAKE_${qt_package}_MODULE_PATCH_VERSION "${${package_name}_VERSION_PATCH}") 36 | endif() 37 | endforeach() 38 | 39 | include("${_Qt6CTestMacros}") 40 | 41 | set(module_includes 42 | WebSockets QWebSocket 43 | ) 44 | 45 | _qt_internal_test_module_includes( 46 | ${module_includes} 47 | ) 48 | -------------------------------------------------------------------------------- /tests/auto/qml/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from qml.pro. 5 | 6 | if(NOT UIKIT) 7 | add_subdirectory(qmlwebsockets) 8 | endif() 9 | -------------------------------------------------------------------------------- /tests/auto/qml/qmlwebsockets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from qmlwebsockets.pro. 5 | 6 | ##################################################################### 7 | ## tst_qmlwebsockets Test: 8 | ##################################################################### 9 | file(GLOB_RECURSE test_data_glob 10 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 11 | *.qml) 12 | list(APPEND test_data ${test_data_glob}) 13 | 14 | qt_internal_add_test(tst_qmlwebsockets 15 | QMLTEST 16 | SOURCES 17 | tst_qmlwebsockets.cpp 18 | LIBRARIES 19 | Qt::Gui 20 | TESTDATA ${test_data} 21 | ) 22 | 23 | #### Keys ignored in scope 1:.:.:qmlwebsockets.pro:: 24 | # DEPLOYMENT = "importFiles" 25 | # TEMPLATE = "app" 26 | # importFiles.path = "." 27 | -------------------------------------------------------------------------------- /tests/auto/qml/qmlwebsockets/tst_qmlwebsockets.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | #include 5 | QUICK_TEST_MAIN(qmlwebsockets) 6 | -------------------------------------------------------------------------------- /tests/auto/websockets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from websockets.pro. 5 | 6 | add_subdirectory(qwebsocketcorsauthenticator) 7 | add_subdirectory(qwebsocket) 8 | add_subdirectory(qwebsocketserver) 9 | if(QT_FEATURE_private_tests) 10 | add_subdirectory(websocketprotocol) 11 | add_subdirectory(dataprocessor) 12 | add_subdirectory(websocketframe) 13 | add_subdirectory(handshakerequest) 14 | add_subdirectory(handshakeresponse) 15 | add_subdirectory(qdefaultmaskgenerator) 16 | endif() 17 | -------------------------------------------------------------------------------- /tests/auto/websockets/dataprocessor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from dataprocessor.pro. 5 | 6 | if(NOT QT_FEATURE_private_tests) 7 | return() 8 | endif() 9 | 10 | ##################################################################### 11 | ## tst_dataprocessor Test: 12 | ##################################################################### 13 | 14 | qt_internal_add_test(tst_dataprocessor 15 | SOURCES 16 | tst_dataprocessor.cpp 17 | LIBRARIES 18 | Qt::WebSocketsPrivate 19 | ) 20 | 21 | #### Keys ignored in scope 1:.:.:dataprocessor.pro:: 22 | # TEMPLATE = "app" 23 | # _REQUIREMENTS = "qtConfig(private_tests)" 24 | -------------------------------------------------------------------------------- /tests/auto/websockets/handshakerequest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from handshakerequest.pro. 5 | 6 | if(NOT QT_FEATURE_private_tests) 7 | return() 8 | endif() 9 | 10 | ##################################################################### 11 | ## tst_handshakerequest Test: 12 | ##################################################################### 13 | 14 | qt_internal_add_test(tst_handshakerequest 15 | SOURCES 16 | tst_handshakerequest.cpp 17 | LIBRARIES 18 | Qt::NetworkPrivate 19 | Qt::WebSocketsPrivate 20 | ) 21 | 22 | #### Keys ignored in scope 1:.:.:handshakerequest.pro:: 23 | # TEMPLATE = "app" 24 | # _REQUIREMENTS = "qtConfig(private_tests)" 25 | -------------------------------------------------------------------------------- /tests/auto/websockets/handshakeresponse/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from handshakeresponse.pro. 5 | 6 | if(NOT QT_FEATURE_private_tests) 7 | return() 8 | endif() 9 | 10 | ##################################################################### 11 | ## tst_handshakeresponse Test: 12 | ##################################################################### 13 | 14 | qt_internal_add_test(tst_handshakeresponse 15 | SOURCES 16 | tst_handshakeresponse.cpp 17 | LIBRARIES 18 | Qt::NetworkPrivate 19 | Qt::WebSocketsPrivate 20 | ) 21 | 22 | #### Keys ignored in scope 1:.:.:handshakeresponse.pro:: 23 | # TEMPLATE = "app" 24 | # _REQUIREMENTS = "qtConfig(private_tests)" 25 | -------------------------------------------------------------------------------- /tests/auto/websockets/handshakeresponse/tst_handshakeresponse.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "private/qwebsockethandshakerequest_p.h" 11 | #include "private/qwebsockethandshakeresponse_p.h" 12 | #include "private/qwebsocketprotocol_p.h" 13 | #include "QtWebSockets/qwebsocketprotocol.h" 14 | 15 | QT_USE_NAMESPACE 16 | 17 | Q_DECLARE_METATYPE(QWebSocketProtocol::CloseCode) 18 | Q_DECLARE_METATYPE(QWebSocketProtocol::OpCode) 19 | 20 | class tst_HandshakeResponse : public QObject 21 | { 22 | Q_OBJECT 23 | 24 | public: 25 | tst_HandshakeResponse(); 26 | 27 | private Q_SLOTS: 28 | void initTestCase(); 29 | void cleanupTestCase(); 30 | void init(); 31 | void cleanup(); 32 | 33 | void tst_date_response(); 34 | }; 35 | 36 | tst_HandshakeResponse::tst_HandshakeResponse() 37 | {} 38 | 39 | void tst_HandshakeResponse::initTestCase() 40 | { 41 | } 42 | 43 | void tst_HandshakeResponse::cleanupTestCase() 44 | {} 45 | 46 | void tst_HandshakeResponse::init() 47 | { 48 | qRegisterMetaType("QWebSocketProtocol::OpCode"); 49 | qRegisterMetaType("QWebSocketProtocol::CloseCode"); 50 | } 51 | 52 | void tst_HandshakeResponse::cleanup() 53 | { 54 | } 55 | 56 | void tst_HandshakeResponse::tst_date_response() 57 | { 58 | QWebSocketHandshakeRequest request(80, false); 59 | QByteArray bytes = "GET / HTTP/1.1\r\nHost: example.com\r\nSec-WebSocket-Version: 13\r\n" 60 | "Sec-WebSocket-Key: AVDFBDDFF\r\n" 61 | "Upgrade: websocket\r\n" 62 | "Connection: Upgrade\r\n\r\n"; 63 | request.readHandshake(bytes, 8 * 1024); 64 | 65 | QWebSocketHandshakeResponse response(request, "example.com", true, 66 | QList() << QWebSocketProtocol::Version13, 67 | QList(), 68 | QList()); 69 | QString data; 70 | QTextStream output(&data); 71 | output << response; 72 | 73 | QStringList list = data.split("\r\n"); 74 | int index = list.indexOf(QRegularExpression("Date:.*")); 75 | QVERIFY(index > -1); 76 | QVERIFY(QLocale::c().toDateTime(list[index], "'Date:' ddd, dd MMM yyyy hh:mm:ss 'GMT'").isValid()); 77 | } 78 | 79 | QTEST_MAIN(tst_HandshakeResponse) 80 | 81 | #include "tst_handshakeresponse.moc" 82 | -------------------------------------------------------------------------------- /tests/auto/websockets/qdefaultmaskgenerator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from qdefaultmaskgenerator.pro. 5 | 6 | if(NOT QT_FEATURE_private_tests) 7 | return() 8 | endif() 9 | 10 | ##################################################################### 11 | ## tst_defaultmaskgenerator Test: 12 | ##################################################################### 13 | 14 | qt_internal_add_test(tst_defaultmaskgenerator 15 | SOURCES 16 | tst_defaultmaskgenerator.cpp 17 | LIBRARIES 18 | Qt::WebSocketsPrivate 19 | ) 20 | 21 | #### Keys ignored in scope 1:.:.:qdefaultmaskgenerator.pro:: 22 | # TEMPLATE = "app" 23 | # _REQUIREMENTS = "qtConfig(private_tests)" 24 | -------------------------------------------------------------------------------- /tests/auto/websockets/qdefaultmaskgenerator/tst_defaultmaskgenerator.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "private/qdefaultmaskgenerator_p.h" 11 | 12 | QT_USE_NAMESPACE 13 | 14 | class tst_QDefaultMaskGenerator : public QObject 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | tst_QDefaultMaskGenerator(); 20 | 21 | private Q_SLOTS: 22 | void initTestCase(); 23 | void cleanupTestCase(); 24 | void init(); 25 | void cleanup(); 26 | 27 | void tst_randomnessWithoutSeed(); 28 | void tst_randomnessWithSeed(); 29 | 30 | private: 31 | }; 32 | 33 | 34 | 35 | tst_QDefaultMaskGenerator::tst_QDefaultMaskGenerator() 36 | { 37 | } 38 | 39 | void tst_QDefaultMaskGenerator::initTestCase() 40 | { 41 | } 42 | 43 | void tst_QDefaultMaskGenerator::cleanupTestCase() 44 | { 45 | } 46 | 47 | void tst_QDefaultMaskGenerator::init() 48 | { 49 | } 50 | 51 | void tst_QDefaultMaskGenerator::cleanup() 52 | { 53 | } 54 | 55 | void tst_QDefaultMaskGenerator::tst_randomnessWithoutSeed() 56 | { 57 | //generate two series of data, and see if they differ 58 | { 59 | QDefaultMaskGenerator generator; 60 | 61 | QList series1, series2; 62 | for (int i = 0; i < 1000; ++i) 63 | series1 << generator.nextMask(); 64 | for (int i = 0; i < 1000; ++i) 65 | series2 << generator.nextMask(); 66 | 67 | QVERIFY(series1 != series2); 68 | } 69 | } 70 | 71 | void tst_QDefaultMaskGenerator::tst_randomnessWithSeed() 72 | { 73 | //generate two series of data, and see if they differ 74 | //the generator is seeded 75 | { 76 | QDefaultMaskGenerator generator; 77 | generator.seed(); 78 | 79 | QList series1, series2; 80 | for (int i = 0; i < 1000; ++i) 81 | series1 << generator.nextMask(); 82 | for (int i = 0; i < 1000; ++i) 83 | series2 << generator.nextMask(); 84 | 85 | QVERIFY(series1 != series2); 86 | } 87 | //generates two series of data with 2 distinct generators 88 | //both generators are seeded 89 | { 90 | QDefaultMaskGenerator generator1, generator2; 91 | generator1.seed(); 92 | generator2.seed(); 93 | 94 | QList series1, series2; 95 | for (int i = 0; i < 1000; ++i) { 96 | series1 << generator1.nextMask(); 97 | series2 << generator2.nextMask(); 98 | } 99 | 100 | QVERIFY(series1 != series2); 101 | } 102 | //generates two series of data with 2 distinct generators 103 | //only one of the two is seeded 104 | { 105 | QDefaultMaskGenerator generator1, generator2; 106 | generator1.seed(); 107 | 108 | QList series1, series2; 109 | for (int i = 0; i < 1000; ++i) { 110 | series1 << generator1.nextMask(); 111 | series2 << generator2.nextMask(); 112 | } 113 | 114 | QVERIFY(series1 != series2); 115 | } 116 | } 117 | 118 | QTEST_MAIN(tst_QDefaultMaskGenerator) 119 | 120 | #include "tst_defaultmaskgenerator.moc" 121 | -------------------------------------------------------------------------------- /tests/auto/websockets/qwebsocket/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from qwebsocket.pro. 5 | 6 | ##################################################################### 7 | ## tst_qwebsocket Test: 8 | ##################################################################### 9 | 10 | qt_internal_add_test(tst_qwebsocket 11 | SOURCES 12 | tst_qwebsocket.cpp 13 | LIBRARIES 14 | Qt::WebSockets 15 | Qt::TestPrivate 16 | BUNDLE_ANDROID_OPENSSL_LIBS 17 | ) 18 | 19 | set(qwebsocketshared_resource_files 20 | "../shared/localhost.cert" 21 | "../shared/localhost.key" 22 | ) 23 | qt_internal_add_resource(tst_qwebsocket "qwebsocketshared" 24 | PREFIX 25 | "/" 26 | BASE 27 | "../shared" 28 | FILES 29 | ${qwebsocketshared_resource_files} 30 | ) 31 | 32 | #### Keys ignored in scope 1:.:.:qwebsocket.pro:: 33 | # TEMPLATE = "app" 34 | -------------------------------------------------------------------------------- /tests/auto/websockets/qwebsocketcorsauthenticator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from qwebsocketcorsauthenticator.pro. 5 | 6 | ##################################################################### 7 | ## tst_qwebsocketcorsauthenticator Test: 8 | ##################################################################### 9 | 10 | qt_internal_add_test(tst_qwebsocketcorsauthenticator 11 | SOURCES 12 | tst_qwebsocketcorsauthenticator.cpp 13 | LIBRARIES 14 | Qt::WebSockets 15 | ) 16 | 17 | #### Keys ignored in scope 1:.:.:qwebsocketcorsauthenticator.pro:: 18 | # TEMPLATE = "app" 19 | -------------------------------------------------------------------------------- /tests/auto/websockets/qwebsocketcorsauthenticator/tst_qwebsocketcorsauthenticator.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "QtWebSockets/qwebsocketcorsauthenticator.h" 10 | 11 | QT_USE_NAMESPACE 12 | 13 | class tst_QWebSocketCorsAuthenticator : public QObject 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | tst_QWebSocketCorsAuthenticator(); 19 | 20 | private Q_SLOTS: 21 | void initTestCase(); 22 | void cleanupTestCase(); 23 | void init(); 24 | void cleanup(); 25 | 26 | void tst_initialization(); 27 | }; 28 | 29 | tst_QWebSocketCorsAuthenticator::tst_QWebSocketCorsAuthenticator() 30 | {} 31 | 32 | void tst_QWebSocketCorsAuthenticator::initTestCase() 33 | { 34 | } 35 | 36 | void tst_QWebSocketCorsAuthenticator::cleanupTestCase() 37 | {} 38 | 39 | void tst_QWebSocketCorsAuthenticator::init() 40 | { 41 | } 42 | 43 | void tst_QWebSocketCorsAuthenticator::cleanup() 44 | { 45 | } 46 | 47 | void tst_QWebSocketCorsAuthenticator::tst_initialization() 48 | { 49 | { 50 | QWebSocketCorsAuthenticator authenticator((QString())); 51 | 52 | QCOMPARE(authenticator.allowed(), true); 53 | QCOMPARE(authenticator.origin(), QString()); 54 | } 55 | { 56 | QWebSocketCorsAuthenticator authenticator(QStringLiteral("com.somesite")); 57 | 58 | QCOMPARE(authenticator.allowed(), true); 59 | QCOMPARE(authenticator.origin(), QStringLiteral("com.somesite")); 60 | 61 | QWebSocketCorsAuthenticator other(authenticator); 62 | QCOMPARE(other.origin(), authenticator.origin()); 63 | QCOMPARE(other.allowed(), authenticator.allowed()); 64 | 65 | authenticator.setAllowed(false); 66 | QVERIFY(!authenticator.allowed()); 67 | QCOMPARE(other.allowed(), true); //make sure other is a real copy 68 | 69 | authenticator.setAllowed(true); 70 | QVERIFY(authenticator.allowed()); 71 | 72 | authenticator.setAllowed(false); 73 | other = authenticator; 74 | QCOMPARE(other.origin(), authenticator.origin()); 75 | QCOMPARE(other.allowed(), authenticator.allowed()); 76 | } 77 | } 78 | 79 | QTEST_MAIN(tst_QWebSocketCorsAuthenticator) 80 | 81 | #include "tst_qwebsocketcorsauthenticator.moc" 82 | 83 | -------------------------------------------------------------------------------- /tests/auto/websockets/qwebsocketserver/BLACKLIST: -------------------------------------------------------------------------------- 1 | # QTBUG-102713 2 | [tst_scheme] 3 | android 4 | [tst_handshakeTimeout] 5 | android 6 | -------------------------------------------------------------------------------- /tests/auto/websockets/qwebsocketserver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from qwebsocketserver.pro. 5 | 6 | ##################################################################### 7 | ## tst_qwebsocketserver Test: 8 | ##################################################################### 9 | 10 | qt_internal_add_test(tst_qwebsocketserver 11 | SOURCES 12 | tst_qwebsocketserver.cpp 13 | LIBRARIES 14 | Qt::WebSockets 15 | BUNDLE_ANDROID_OPENSSL_LIBS 16 | ) 17 | 18 | # Resources: 19 | set(qwebsocketshared_resource_files 20 | "../shared/localhost.cert" 21 | "../shared/localhost.key" 22 | ) 23 | 24 | qt_internal_add_resource(tst_qwebsocketserver "qwebsocketshared" 25 | PREFIX 26 | "/" 27 | BASE 28 | "../shared" 29 | FILES 30 | ${qwebsocketshared_resource_files} 31 | ) 32 | 33 | 34 | #### Keys ignored in scope 1:.:.:qwebsocketserver.pro:: 35 | # TEMPLATE = "app" 36 | 37 | ## Scopes: 38 | ##################################################################### 39 | 40 | qt_internal_extend_target(tst_qwebsocketserver CONDITION boot2qt 41 | DEFINES 42 | SHOULD_CHECK_SYSCALL_SUPPORT 43 | ) 44 | -------------------------------------------------------------------------------- /tests/auto/websockets/shared/localhost.cert: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIC+zCCAeOgAwIBAgIJAP26rumH9qOkMA0GCSqGSIb3DQEBBQUAMBQxEjAQBgNV 3 | BAMMCWxvY2FsaG9zdDAeFw0xMzExMDYxNjU4NTRaFw0yMzExMDQxNjU4NTRaMBQx 4 | EjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC 5 | ggEBALgagHqEqWr4WH+MFBQE+BWZri5UUn/QPORN2pUB1lWMzeDCM5YMc/D1dhUG 6 | 7zg5I9QO5Ut1YcoVO25OAseddgVaIFXPNyEG2nUTz53xx3pyqp3WtQkYCRAQzI8K 7 | IFIzBSD+nJNl+8gBld7Fe+4d8bFCwfXspQBJ2RY8SQ6tjRFVKHN7haLsD+WV3AFg 8 | siWkCxeXxVLNI69cuLwV7bEsv6U1N1yNROvRpu4yJcaNnu36kJFbORPhNfy6qJGX 9 | i0A30dYdMoLhtCN3Qf/XwGyS84Rs2XXduNlBdUgbpluY2r2x3Gz32hIwsHHcPzX6 10 | O9nwVPQ8k29lfC8yPmAWA9vPiBUCAwEAAaNQME4wHQYDVR0OBBYEFJZESCN01tY3 11 | MgXxmqiUBNPxsgiKMB8GA1UdIwQYMBaAFJZESCN01tY3MgXxmqiUBNPxsgiKMAwG 12 | A1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAHylCJYED9PqLB9FE4A0CRfy 13 | BdxIqOK+UExxxkU1DeN7kM4U2+E0G85nqBLOL34BDj8LDKJH9WC7L9jMV8T3Upbg 14 | +RrTGiIcyjsL18L2KWeOia1R6VVAQcZrqoWv+QXyVvIi8IpTOE074C6+Vzx6XYMe 15 | CpW4jcdfmn39oVeMXxz9+8wD7CWeCT+SMj8tt+OB1XjQwdEG03vb6ArtnuJT77VI 16 | 3I090OtKksBE5hy1H9N2E3wxhFTxC+DI5sc7Bj87v3blL4Z3DvRUEHwQHcDccQ0D 17 | ERUEcSyn1YGSlDVbVf3CzH4WXxddUBmaSHf4JTuAMy0C0A6IWuMP+rVVvVMIXNM= 18 | -----END CERTIFICATE----- 19 | -------------------------------------------------------------------------------- /tests/auto/websockets/shared/localhost.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEogIBAAKCAQEAuBqAeoSpavhYf4wUFAT4FZmuLlRSf9A85E3alQHWVYzN4MIz 3 | lgxz8PV2FQbvODkj1A7lS3VhyhU7bk4Cx512BVogVc83IQbadRPPnfHHenKqnda1 4 | CRgJEBDMjwogUjMFIP6ck2X7yAGV3sV77h3xsULB9eylAEnZFjxJDq2NEVUoc3uF 5 | ouwP5ZXcAWCyJaQLF5fFUs0jr1y4vBXtsSy/pTU3XI1E69Gm7jIlxo2e7fqQkVs5 6 | E+E1/LqokZeLQDfR1h0yguG0I3dB/9fAbJLzhGzZdd242UF1SBumW5javbHcbPfa 7 | EjCwcdw/Nfo72fBU9DyTb2V8LzI+YBYD28+IFQIDAQABAoIBADADmWZamuSvCEWb 8 | ftEJyrm3btneW/XBlV/lfhBGfmOpaTgo7dNARCyfl8A8Ir+DB3kSuXJIlsxhZTKL 9 | XeY5hsI2kyBN/o66ftbx57/FgsTIiv7HNEe+4P4zo2Xaujs12yyTuromatfqse97 10 | iaq8XIBibLt6kD3XBKrr5hHR6WyPW9F7sM91e/1OGTXBt9URvnnHqcimJ8Wvto5p 11 | SMFlud8JXMmARhWaIfqQIcNYmNEHea0LfOZVerTOPE7IZd5coM91mr71lzoxs9Ik 12 | bRMbqgyAMXEJV3ynEH2LjjJZo1bVb8Va45QqqOQ4FtL46n1Z+EVUXyhCHGepwyOv 13 | uAru0wECgYEA3CnM252417At+N9Zq4KtBJ8tIEXKqvK1Bl5aZSqaJClywjCttR2l 14 | lRAlIRAmqHCQuxLDDfLfiJh6xgZsjr4MhksuyKc7DKssfWW+XCd+5GaaMoMvJXhs 15 | caJdhNSHzpnLPi++tJBYHwHa354D5PJ3eItzLkmuVyhmc3plNbkBGLECgYEA1hIX 16 | mA9KadVG9VkaDci+xo1p0ACb5ccHAvmA8+fzb0H09yKw5bCSpNGeHj4Qv5ZFqsUm 17 | 96NWYEB38ezupWqWMFd9zr1kD2s3r6Kpq1TS6xuDPapyiXaKpcH1ys7IWZkinCkN 18 | oxhPHcQbFu9/CN2zIVFKvF5P98Rh0+wO7fgL/qUCgYAyleAd7cVUuYQ2lIrz31iF 19 | oVUq/x4r3Qw+5Fr8t6cm++cEO08OODudXlJJoH5hYUu/z/XFNLKrne1Hpp42xe/2 20 | wzuCmvn0VTgpr8DnR6PeMrznMkEY6Oxxx46ZQIPbsnaCWVIGBsxYg4KYsqPObO+K 21 | YPAcCI3oNL4ldk/e4h0gYQKBgHm+4FxClfeKrEhs3DxqptUVJ9B8CC2t+3bdn1EX 22 | 4YKs6DyFJkX7HetOq7ZXZf8P3583cOn1ovIquAyGy1KYQ8JKf+pMG9QJDip9QDGI 23 | lEvR4dn4ThuPp1qN7NPitl7+kIhvcKoI8TXkieOJYZ4ROAcCzJZErQYkUd7MqdD8 24 | +RVhAoGAcWC9HRDhxjs4shaBlYi8Lfp3dV4f/4UgYosdFAZ26atwHz+sCLHwwg1j 25 | 6t5Zxy9oEB89S5v5hkgO8//JmopvISSokdvocASMdKE+OmS3JfBmhQK9qVBW/vv/ 26 | ut2bhPjEzIJyNFKX3xnGI8PREcR2eY+WLhIZ5KiR61tGpktJ4bg= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /tests/auto/websockets/websocketframe/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from websocketframe.pro. 5 | 6 | if(NOT QT_FEATURE_private_tests) 7 | return() 8 | endif() 9 | 10 | ##################################################################### 11 | ## tst_websocketframe Test: 12 | ##################################################################### 13 | 14 | qt_internal_add_test(tst_websocketframe 15 | SOURCES 16 | tst_websocketframe.cpp 17 | LIBRARIES 18 | Qt::WebSocketsPrivate 19 | ) 20 | 21 | #### Keys ignored in scope 1:.:.:websocketframe.pro:: 22 | # TEMPLATE = "app" 23 | # _REQUIREMENTS = "qtConfig(private_tests)" 24 | -------------------------------------------------------------------------------- /tests/auto/websockets/websocketprotocol/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from websocketprotocol.pro. 5 | 6 | if(NOT QT_FEATURE_private_tests) 7 | return() 8 | endif() 9 | 10 | ##################################################################### 11 | ## tst_websocketprotocol Test: 12 | ##################################################################### 13 | 14 | qt_internal_add_test(tst_websocketprotocol 15 | SOURCES 16 | tst_websocketprotocol.cpp 17 | LIBRARIES 18 | Qt::WebSocketsPrivate 19 | ) 20 | 21 | #### Keys ignored in scope 1:.:.:websocketprotocol.pro:: 22 | # TEMPLATE = "app" 23 | # _REQUIREMENTS = "qtConfig(private_tests)" 24 | -------------------------------------------------------------------------------- /tests/doc/README.qdocinc: -------------------------------------------------------------------------------- 1 | This directory contains autotests and manual tests for the Qt WebSockets 2 | module. 3 | 4 | In addition, Autobahn|Testsuite, a standard test suite for WebSocket 5 | Protocol (RFC 6455), can be used for testing the conformance of Qt 6 | WebSockets. 7 | 8 | http://autobahn.ws/testsuite/ 9 | 10 | Refer to Autobahn|Testsuite installation documentation at 11 | http://autobahn.ws/testsuite/installation.html 12 | 13 | //! [testsuite] 14 | \section1 Testing Qt WebSockets with Autobahn|Testsuite 15 | 16 | 17 | \section2 wstest - fuzzingserver mode 18 | 19 | \code 20 | cd your_build_dir/tests/manual/compliance 21 | qmake your_src_dir/tests/manual/compliance/compliance.pro 22 | make 23 | 24 | cd ~ 25 | wstest -m fuzzingserver 26 | \endcode 27 | 28 | Then, in another terminal: 29 | 30 | \code 31 | cd your_build_dir/tests/manual/compliance 32 | ./tst_compliance 33 | \endcode 34 | 35 | Test results will be generated under ~/reports/clients directory. 36 | Point your browser to ~/reports/clients/index.html. 37 | 38 | 39 | \section2 wstest - fuzzingclient mode 40 | 41 | \code 42 | cd your_build_dir/examples/websockets/echoserver 43 | qmake your_src_dir/examples/websockets/echoserver/echoserver.pro 44 | make 45 | 46 | ./echoserver -p 9001 47 | \endcode 48 | 49 | Then, in another terminal: 50 | 51 | \code 52 | cd ~ 53 | wstest -m fuzzingclient 54 | \endcode 55 | 56 | Test results will be generated under ~/reports/servers directory. 57 | Point your browser to ~/reports/servers/index.html. 58 | //! [testsuite] 59 | -------------------------------------------------------------------------------- /tests/global/global.cfg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/manual/compliance/compliance.pro: -------------------------------------------------------------------------------- 1 | CONFIG += console 2 | CONFIG += testcase 3 | CONFIG -= app_bundle 4 | 5 | TEMPLATE = app 6 | 7 | TARGET = tst_compliance 8 | 9 | QT = websockets testlib 10 | 11 | SOURCES += tst_compliance.cpp 12 | -------------------------------------------------------------------------------- /tests/manual/compliance/tst_compliance.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Kurt Pattyn . 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class tst_ComplianceTest : public QObject 12 | { 13 | Q_OBJECT 14 | 15 | private Q_SLOTS: 16 | void cleanupTestCase(); 17 | 18 | void autobahnTest_data(); 19 | void autobahnTest(); 20 | }; 21 | 22 | static const QUrl baseUrl { "ws://localhost:9001" }; 23 | static const auto agent = QStringLiteral("QtWebSockets/" QT_VERSION_STR); 24 | 25 | void tst_ComplianceTest::cleanupTestCase() 26 | { 27 | QWebSocket webSocket; 28 | QSignalSpy spy(&webSocket, &QWebSocket::disconnected); 29 | auto url = baseUrl; 30 | url.setPath(QStringLiteral("/updateReports")); 31 | QUrlQuery query; 32 | query.addQueryItem(QStringLiteral("agent"), agent); 33 | url.setQuery(query); 34 | webSocket.open(url); 35 | QVERIFY(spy.wait()); 36 | } 37 | 38 | void tst_ComplianceTest::autobahnTest_data() 39 | { 40 | QTest::addColumn("testCase"); 41 | 42 | // Ask /getCaseCount how many tests we have 43 | QWebSocket webSocket; 44 | QSignalSpy spy(&webSocket, &QWebSocket::disconnected); 45 | 46 | connect(&webSocket, &QWebSocket::textMessageReceived, [](QString message) { 47 | bool ok; 48 | const auto numberOfTestCases = message.toInt(&ok); 49 | if (!ok) 50 | QSKIP("Unable to parse /getCaseCount result"); 51 | for (auto i = 1; i <= numberOfTestCases; ++i) 52 | QTest::addRow("%d", i) << i; 53 | }); 54 | 55 | auto url = baseUrl; 56 | url.setPath(QStringLiteral("/getCaseCount")); 57 | webSocket.open(url); 58 | if (!spy.wait()) 59 | QSKIP("AutoBahn test server didn't deliver case-count"); 60 | } 61 | 62 | void tst_ComplianceTest::autobahnTest() 63 | { 64 | QFETCH(int, testCase); 65 | QWebSocket webSocket; 66 | QSignalSpy spy(&webSocket, &QWebSocket::disconnected); 67 | connect(&webSocket, &QWebSocket::textMessageReceived, 68 | &webSocket, &QWebSocket::sendTextMessage); 69 | connect(&webSocket, &QWebSocket::binaryMessageReceived, 70 | &webSocket, &QWebSocket::sendBinaryMessage); 71 | 72 | // Ask /runCase?case=&agent= to run the test-case. 73 | auto url = baseUrl; 74 | url.setPath(QStringLiteral("/runCase")); 75 | QUrlQuery query; 76 | query.addQueryItem(QStringLiteral("case"), QString::number(testCase)); 77 | query.addQueryItem(QStringLiteral("agent"), agent); 78 | url.setQuery(query); 79 | webSocket.open(url); 80 | QVERIFY(spy.wait()); 81 | } 82 | 83 | QTEST_MAIN(tst_ComplianceTest) 84 | 85 | #include "tst_compliance.moc" 86 | -------------------------------------------------------------------------------- /tests/manual/manual.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | SUBDIRS += \ 4 | compliance \ 5 | websockets 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/manual/websockets/websockets.pro: -------------------------------------------------------------------------------- 1 | CONFIG += console 2 | CONFIG += testcase 3 | CONFIG -= app_bundle 4 | 5 | TEMPLATE = app 6 | 7 | TARGET = tst_websockets 8 | 9 | QT = websockets testlib 10 | 11 | SOURCES += tst_websockets.cpp 12 | --------------------------------------------------------------------------------