-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWebSocketConnection.h
More file actions
58 lines (46 loc) · 1.66 KB
/
WebSocketConnection.h
File metadata and controls
58 lines (46 loc) · 1.66 KB
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
#ifndef WEBSOCKETCONNECTION_H
#define WEBSOCKETCONNECTION_H
#include <QObject>
#include <QTcpSocket>
#include <QTimer>
class WebSocketConnection : public QObject {
Q_OBJECT
public:
// Updated constructor with optional delayed ownership
explicit WebSocketConnection(QTcpSocket *socket, QObject *parent = nullptr, bool takeOwnership = true);
void sendTextMessage(const QString &message);
void sendPongMessage(const QByteArray &payload);
void sendPingMessage(const QByteArray &payload = QByteArray());
bool performHandshake(const QByteArray &requestData);
// New method to take ownership after handshake
void takeSocketOwnership();
// Start automatic ping cycle (telescope initiates pings)
void startPingCycle(int intervalMs = 5000);
void stopPingCycle();
// Debug and monitoring methods
void resetPingState();
void verifyTimerSetup();
void verifySocketOwnership();
signals:
void textMessageReceived(const QString &message);
void pingReceived(const QByteArray &payload);
void pongReceived(const QByteArray &payload);
void disconnected();
void pingTimeout();
private slots:
void handleData();
void onPingTimeout();
void sendAutomaticPing();
private:
QTcpSocket *m_socket;
bool m_handshakeComplete;
QTimer *m_pingTimeoutTimer;
QTimer *m_autoPingTimer;
bool m_waitingForPong;
QByteArray m_pendingData; // For handling incomplete frames
int m_pingCounter;
int m_missedPongCount;
void sendFrame(quint8 opcode, const QByteArray &payload, bool masked = false);
int processFrame(const QByteArray &data);
};
#endif // WEBSOCKETCONNECTION_H