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
23 #include <QAbstractSocket>
24 #include <QHostAddress>
25 #ifndef QT_NO_NETWORKPROXY
26 #include <QNetworkProxy>
29 #include "qwebsocketsglobal.h"
30 #include "qwebsocketprotocol.h"
35 class QWebSocketPrivate;
37 class Q_WEBSOCKETS_EXPORT QWebSocket:public QObject
42 explicit QWebSocket(QString origin = QString(), QWebSocketProtocol::Version version = QWebSocketProtocol::V_LATEST, QObject *parent = 0);
43 virtual ~QWebSocket();
46 QAbstractSocket::SocketError error() const;
47 QString errorString() const;
50 QHostAddress localAddress() const;
51 quint16 localPort() const;
52 QAbstractSocket::PauseModes pauseMode() const;
53 QHostAddress peerAddress() const;
54 QString peerName() const;
55 quint16 peerPort() const;
56 #ifndef QT_NO_NETWORKPROXY
57 QNetworkProxy proxy() const;
58 void setProxy(const QNetworkProxy &networkProxy);
60 qint64 readBufferSize() const;
61 void setReadBufferSize(qint64 size);
64 void setPauseMode(QAbstractSocket::PauseModes pauseMode);
66 void setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value);
67 QVariant socketOption(QAbstractSocket::SocketOption option);
68 QAbstractSocket::SocketState state() const;
70 bool waitForConnected(int msecs = 30000);
71 bool waitForDisconnected(int msecs = 30000);
73 QWebSocketProtocol::Version version();
74 QString resourceName();
80 qint64 write(const char *message); //send data as text
81 qint64 write(const char *message, qint64 maxSize); //send data as text
82 qint64 write(const QString &message); //send data as text
83 qint64 write(const QByteArray &data); //send data as binary
86 virtual void close(QWebSocketProtocol::CloseCode closeCode = QWebSocketProtocol::CC_NORMAL, QString reason = QString());
87 virtual void open(const QUrl &url, bool mask = true);
94 void stateChanged(QAbstractSocket::SocketState state);
95 #ifndef QT_NO_NETWORKPROXY
96 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *pAuthenticator);
98 void readChannelFinished();
99 void textFrameReceived(QString frame, bool isLastFrame);
100 void binaryFrameReceived(QByteArray frame, bool isLastFrame);
101 void textMessageReceived(QString message);
102 void binaryMessageReceived(QByteArray message);
103 void error(QAbstractSocket::SocketError error);
104 void pong(quint64 elapsedTime);
107 Q_DISABLE_COPY(QWebSocket)
108 QWebSocket(QTcpSocket *pTcpSocket, QWebSocketProtocol::Version version, QObject *parent = 0);
109 QWebSocketPrivate * const d_ptr;
111 friend class QWebSocketPrivate;
116 #endif // QWEBSOCKET_H