2 QWebSockets implements the WebSocket protocol as defined in RFC 6455.
3 Copyright (C) 2013 Kurt Pattyn (pattyn.kurt@gmail.com)
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #ifndef QT_NO_NETWORKPROXY
25 #include <QNetworkProxy>
29 #include <QSslConfiguration>
31 #include "qwebsockets_global.h"
32 #include "qwebsocketprotocol.h"
37 class QWebSocketPrivate;
39 class Q_WEBSOCKETS_EXPORT QWebSocket : public QObject
42 Q_DISABLE_COPY(QWebSocket)
43 Q_DECLARE_PRIVATE(QWebSocket)
46 explicit QWebSocket(const QString &origin = QString(), QWebSocketProtocol::Version version = QWebSocketProtocol::V_LATEST, QObject *parent = Q_NULLPTR);
47 virtual ~QWebSocket();
50 QAbstractSocket::SocketError error() const;
51 QString errorString() const;
54 QHostAddress localAddress() const;
55 quint16 localPort() const;
56 QAbstractSocket::PauseModes pauseMode() const;
57 QHostAddress peerAddress() const;
58 QString peerName() const;
59 quint16 peerPort() const;
60 #ifndef QT_NO_NETWORKPROXY
61 QNetworkProxy proxy() const;
62 void setProxy(const QNetworkProxy &networkProxy);
64 qint64 readBufferSize() const;
65 void setReadBufferSize(qint64 size);
68 void setPauseMode(QAbstractSocket::PauseModes pauseMode);
70 void setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value);
71 QVariant socketOption(QAbstractSocket::SocketOption option);
72 QAbstractSocket::SocketState state() const;
74 bool waitForConnected(int msecs = 30000);
75 bool waitForDisconnected(int msecs = 30000);
77 QWebSocketProtocol::Version version() const;
78 QString resourceName() const;
79 QUrl requestUrl() const;
80 QString origin() const;
81 QString protocol() const;
82 QString extension() const;
84 qint64 write(const char *message); //send data as text
85 qint64 write(const char *message, qint64 maxSize); //send data as text
86 qint64 write(const QString &message); //send data as text
87 qint64 write(const QByteArray &data); //send data as binary
90 void ignoreSslErrors(const QList<QSslError> &errors);
91 void setSslConfiguration(const QSslConfiguration &sslConfiguration);
92 QSslConfiguration sslConfiguration() const;
96 void close(QWebSocketProtocol::CloseCode closeCode = QWebSocketProtocol::CC_NORMAL, const QString &reason = QString());
97 void open(const QUrl &url, bool mask = true);
98 void ping(const QByteArray &payload = QByteArray());
104 void stateChanged(QAbstractSocket::SocketState state);
105 #ifndef QT_NO_NETWORKPROXY
106 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *pAuthenticator);
108 void readChannelFinished();
109 void textFrameReceived(QString frame, bool isLastFrame);
110 void binaryFrameReceived(QByteArray frame, bool isLastFrame);
111 void textMessageReceived(QString message);
112 void binaryMessageReceived(QByteArray message);
113 void error(QAbstractSocket::SocketError error);
114 void pong(quint64 elapsedTime, QByteArray payload);
115 void bytesWritten(qint64 bytes);
118 QWebSocket(QTcpSocket *pTcpSocket, QWebSocketProtocol::Version version, QObject *parent = Q_NULLPTR);
119 QWebSocketPrivate * const d_ptr;
124 #endif // QWEBSOCKET_H