-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtcpserverwrapper.h
38 lines (31 loc) · 1002 Bytes
/
tcpserverwrapper.h
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
#ifndef TCPSERVERWRAPPER_H
#define TCPSERVERWRAPPER_H
#include <QObject>
#include <QTcpServer>
#include <QThread>
class TcpServerWrapper : public QTcpServer{
Q_OBJECT
public:
inline TcpServerWrapper(QObject *parent = 0):QTcpServer(parent){}
virtual ~TcpServerWrapper(){}
private:
virtual void incomingConnection(qintptr handle)override;
};
class TcpConnectionDelegate : public QObject
{
Q_OBJECT
public:
explicit TcpConnectionDelegate(QObject *parent = nullptr);
virtual ~TcpConnectionDelegate();
bool listen(const QHostAddress &address = QHostAddress::Any, quint16 port = 0);
signals:
void sigHasReadyClient(QTcpSocket *);
void sigOnError(QAbstractSocket::SocketError );
private slots:
void onReadyRead();
void onReadyForConnecting();
void onAcceptError(QAbstractSocket::SocketError socketError);
void onClientDestory(QObject* );
private:
QTcpServer* mTcpServer;};
#endif // TCPSERVERWRAPPER_H