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 #include <QAbstractSocket>
25 #include <QHostAddress>
26 #ifndef QT_NO_NETWORKPROXY
27 #include <QNetworkProxy>
30 #include "qwebsocketsglobal.h"
31 #include "qwebsocketprotocol.h"
36 class QWebSocketPrivate;
38 class Q_WEBSOCKETS_EXPORT QWebSocket:public QObject
43 explicit QWebSocket(const QString &origin = QString(), QWebSocketProtocol::Version version = QWebSocketProtocol::V_LATEST, QObject *parent = 0);
44 virtual ~QWebSocket();
47 QAbstractSocket::SocketError error() const;
48 QString errorString() const;
51 QHostAddress localAddress() const;
52 quint16 localPort() const;
53 QAbstractSocket::PauseModes pauseMode() const;
54 QHostAddress peerAddress() const;
55 QString peerName() const;
56 quint16 peerPort() const;
57 #ifndef QT_NO_NETWORKPROXY
58 QNetworkProxy proxy() const;
59 void setProxy(const QNetworkProxy &networkProxy);
61 qint64 readBufferSize() const;
62 void setReadBufferSize(qint64 size);
65 void setPauseMode(QAbstractSocket::PauseModes pauseMode);
67 void setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value);
68 QVariant socketOption(QAbstractSocket::SocketOption option);
69 QAbstractSocket::SocketState state() const;
71 bool waitForConnected(int msecs = 30000);
72 bool waitForDisconnected(int msecs = 30000);
74 QWebSocketProtocol::Version version() const;
75 QString resourceName() const;
76 QUrl requestUrl() const;
77 QString origin() const;
78 QString protocol() const;
79 QString extension() const;
81 qint64 write(const char *message); //send data as text
82 qint64 write(const char *message, qint64 maxSize); //send data as text
83 qint64 write(const QString &message); //send data as text
84 qint64 write(const QByteArray &data); //send data as binary
87 void close(QWebSocketProtocol::CloseCode closeCode = QWebSocketProtocol::CC_NORMAL, const QString &reason = QString());
88 void open(const QUrl &url, bool mask = true);
95 void stateChanged(QAbstractSocket::SocketState state);
96 #ifndef QT_NO_NETWORKPROXY
97 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *pAuthenticator);
99 void readChannelFinished();
100 void textFrameReceived(QString frame, bool isLastFrame);
101 void binaryFrameReceived(QByteArray frame, bool isLastFrame);
102 void textMessageReceived(QString message);
103 void binaryMessageReceived(QByteArray message);
104 void error(QAbstractSocket::SocketError error);
105 void pong(quint64 elapsedTime);
108 Q_DISABLE_COPY(QWebSocket)
109 Q_DECLARE_PRIVATE(QWebSocket)
110 QWebSocket(QTcpSocket *pTcpSocket, QWebSocketProtocol::Version version, QObject *parent = 0);
111 QWebSocketPrivate * const d_ptr;
116 #endif // QWEBSOCKET_H