summaryrefslogtreecommitdiffstats
path: root/examples/network/network-chat/connection.h
diff options
context:
space:
mode:
Diffstat (limited to 'examples/network/network-chat/connection.h')
-rw-r--r--examples/network/network-chat/connection.h25
1 files changed, 14 insertions, 11 deletions
diff --git a/examples/network/network-chat/connection.h b/examples/network/network-chat/connection.h
index a3082247cb..4b063e7def 100644
--- a/examples/network/network-chat/connection.h
+++ b/examples/network/network-chat/connection.h
@@ -12,8 +12,6 @@
#include <QTcpSocket>
#include <QTimer>
-static const int MaxBufferSize = 1024000;
-
class Connection : public QTcpSocket
{
Q_OBJECT
@@ -22,6 +20,7 @@ public:
enum ConnectionState {
WaitingForGreeting,
ReadingGreeting,
+ ProcessingGreeting,
ReadyForUse
};
enum DataType {
@@ -32,14 +31,16 @@ public:
Undefined
};
- Connection(QObject *parent = nullptr);
- Connection(qintptr socketDescriptor, QObject *parent = nullptr);
+ explicit Connection(QObject *parent = nullptr);
+ explicit Connection(qintptr socketDescriptor, QObject *parent = nullptr);
~Connection();
QString name() const;
- void setGreetingMessage(const QString &message);
+ void setGreetingMessage(const QString &message, const QByteArray &uniqueId);
bool sendMessage(const QString &message);
+ QByteArray uniqueId() const;
+
signals:
void readyForUse();
void newMessage(const QString &from, const QString &message);
@@ -59,15 +60,17 @@ private:
QCborStreamReader reader;
QCborStreamWriter writer;
- QString greetingMessage;
- QString username;
+ QString greetingMessage = tr("undefined");
+ QString username = tr("unknown");
QTimer pingTimer;
QElapsedTimer pongTime;
QString buffer;
- ConnectionState state;
- DataType currentDataType;
- int transferTimerId;
- bool isGreetingMessageSent;
+ QByteArray localUniqueId;
+ QByteArray peerUniqueId;
+ ConnectionState state = WaitingForGreeting;
+ DataType currentDataType = Undefined;
+ int transferTimerId = -1;
+ bool isGreetingMessageSent = false;
};
#endif