Now we are starting to get into the realm of network and the internet. WebSockets are a protocol that allows two-way data exchange between a web browser or client and a server without polling. You can stream data or send data at any time. Qt has support for WebSockets through the use of the QWebSocket
API. Like normal TCP sockets, QWebSockets
needs a server.
QWebSocketServer
can work in two modes: non-secure and SSL. We start by addingwebsockets
to the .pro
file so qmake
sets up the proper library and header paths:
QT += websockets
Then include the QWebSocketServer
header file:
#include<QtWebSockets/QWebSocketServer>
The source code can be found on the Git repository under the Chapter07-3
directory, in the cp7
branch.
To create a QWebSocketServer
, it takes a server name as a string, a mode, and a parent object. The mode can be SecureMode
or NonSecureMode
.
SecureMode
is is like HTTPS, uses SSL, and the protocol is wss. NonSecureMode...