-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.h
44 lines (38 loc) · 1.14 KB
/
server.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
39
40
41
42
43
44
#ifndef SERVER_H
#define SERVER_H
#include <QObject>
#include <QTcpServer>
#include <QThread>
#include <QDebug>
#include <QTcpSocket>
#include <QList>
#include <chrono>
#include <thread>
class Server : public QObject
{
Q_OBJECT
public:
explicit Server(QObject *parent = nullptr);
~Server();
public:
void listen();
void appendNewConnection(QTcpSocket *client);
void writeToClients(QString msg, QString type);
//某一个客户端断开连接时,发送消息给其他客户端
void writeToClients(QString msg, QString type, QTcpSocket *currentClient);
signals:
void addUdpClient(QTcpSocket *client, QHostAddress ip, quint16 udpPort);
void removeUdpClient(QTcpSocket *client);
private slots:
void initServer(int port);
void newConnection();
void clientDisconnected();
void readFromClient();
private:
QTcpServer *tcpServer = nullptr; //tcp服务
QList<QTcpSocket *> clients; //保存客户端列表
int port; //保存监听端口
QString source; //播放链接
bool isSourceSet = false; //是否已经有播放链接
};
#endif // SERVER_H