Renamed qwebsocket.pri to qwebsockets.pri
[contrib/qtwebsockets.git] / src / qwebsocket.h
1 /*
2 QWebSockets implements the WebSocket protocol as defined in RFC 6455.
3 Copyright (C) 2013 Kurt Pattyn (pattyn.kurt@gmail.com)
4
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.
9
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.
14
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
18 */
19
20 #ifndef QWEBSOCKET_H
21 #define QWEBSOCKET_H
22
23 #include <QUrl>
24 #include <QAbstractSocket>
25 #include <QHostAddress>
26 #ifndef QT_NO_NETWORKPROXY
27 #include <QNetworkProxy>
28 #endif
29 #include <QTime>
30 #include "qwebsocketsglobal.h"
31 #include "qwebsocketprotocol.h"
32
33 QT_BEGIN_NAMESPACE
34
35 class QTcpSocket;
36 class QWebSocketPrivate;
37
38 class Q_WEBSOCKETS_EXPORT QWebSocket:public QObject
39 {
40         Q_OBJECT
41
42 public:
43         explicit QWebSocket(QString origin = QString(), QWebSocketProtocol::Version version = QWebSocketProtocol::V_LATEST, QObject *parent = 0);
44         virtual ~QWebSocket();
45
46         void abort();
47         QAbstractSocket::SocketError error() const;
48         QString errorString() const;
49         bool flush();
50         bool isValid();
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);
60 #endif
61         qint64 readBufferSize() const;
62         void setReadBufferSize(qint64 size);
63
64         void resume();
65         void setPauseMode(QAbstractSocket::PauseModes pauseMode);
66
67         void setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value);
68         QVariant socketOption(QAbstractSocket::SocketOption option);
69         QAbstractSocket::SocketState state() const;
70
71         bool waitForConnected(int msecs = 30000);
72         bool waitForDisconnected(int msecs = 30000);
73
74         QWebSocketProtocol::Version version();
75         QString resourceName();
76         QUrl requestUrl();
77         QString origin();
78         QString protocol();
79         QString extension();
80
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
85
86 public Q_SLOTS:
87         virtual void close(QWebSocketProtocol::CloseCode closeCode = QWebSocketProtocol::CC_NORMAL, QString reason = QString());
88         virtual void open(const QUrl &url, bool mask = true);
89         void ping();
90
91 Q_SIGNALS:
92         void aboutToClose();
93         void connected();
94         void disconnected();
95         void stateChanged(QAbstractSocket::SocketState state);
96 #ifndef QT_NO_NETWORKPROXY
97         void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *pAuthenticator);
98 #endif
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);
106
107 private:
108         Q_DISABLE_COPY(QWebSocket)
109         QWebSocket(QTcpSocket *pTcpSocket, QWebSocketProtocol::Version version, QObject *parent = 0);
110         QWebSocketPrivate * const d_ptr;
111
112         friend class QWebSocketPrivate;
113 };
114
115 QT_END_NAMESPACE
116
117 #endif // QWEBSOCKET_H