blob: 136c839deceb8d3f40351b5e84f45e62230e13c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/**
* @file websocketserver.h
* @author Kurt Pattyn (pattyn.kurt@gmail.com)
* @brief Defines the WebSocketServer class.
*/
#ifndef QWEBSOCKETSERVER_H
#define QWEBSOCKETSERVER_H
#include <QObject>
#include <QQueue>
#include <QString>
#include <QHostAddress>
#include "qwebsocket.h"
class QTcpServer;
class QWebSocketServer : public QObject
{
Q_OBJECT
public:
explicit QWebSocketServer(const QString &serverName, QObject *parent = 0);
virtual ~QWebSocketServer();
void close();
QString errorString() const;
bool hasPendingConnections() const;
bool isListening() const;
bool listen(const QHostAddress &address = QHostAddress::Any, quint16 port = 0);
int maxPendingConnections() const;
virtual QWebSocket *nextPendingConnection();
QNetworkProxy proxy() const;
QHostAddress serverAddress() const;
QAbstractSocket::SocketError serverError() const;
quint16 serverPort() const;
void setMaxPendingConnections(int numConnections);
void setProxy(const QNetworkProxy &networkProxy);
bool setSocketDescriptor(int socketDescriptor);
int socketDescriptor() const;
bool waitForNewConnection(int msec = 0, bool *timedOut = 0);
QList<QWebSocketProtocol::Version> supportedVersions() const;
QList<QString> supportedProtocols() const;
QList<QString> supportedExtensions() const;
protected:
virtual bool isOriginAllowed(const QString &origin) const;
Q_SIGNALS:
void newConnection();
private Q_SLOTS:
void onNewConnection();
void onCloseConnection();
void handshakeReceived();
private:
Q_DISABLE_COPY(QWebSocketServer)
QTcpServer *m_pTcpServer;
QString m_serverName;
QQueue<QWebSocket *> m_pendingConnections;
void addPendingConnection(QWebSocket *pWebSocket);
};
#endif // QWEBSOCKETSERVER_H
|