forked from ThibeVanOrshaegen/P2P-chatServer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tcpclient.h
50 lines (40 loc) · 1.21 KB
/
tcpclient.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
45
46
47
48
49
50
#ifndef TCPCLIENT_H
#define TCPCLIENT_H
#include <QCoreApplication>
#include <QObject>
#include <QTcpSocket>
#include <qtcpserver.h>
#include <QAbstractSocket>
#include <QDebug>
#include <QInputDialog>
#include "userinterface.h"
#include <string>
class TcpClient : public QObject
{
Q_OBJECT
public:
explicit TcpClient(QObject *parent = nullptr, QString NickName = nullptr);
~TcpClient(){};
std::string getPeers(void);
void firstConnect(std::string firstIp, int firstPort);
QString getNickName(void) {return nickname;};
QString getIP(void) {if(!m_sockets.empty()){return m_sockets.first()->localAddress().toString();} else{return "";}};
quint16 getPort(void) {return server->serverPort();};
void setNickName(QString NickName){nickname = NickName;};
signals:
void sendMessage(QString message);
void newMessageReceived(QString message);
void newConnection(QTcpSocket *socket);
public slots:
void handleNewConnection();
void sendToAll(QString message);
void readFromAll();
private:
QList<QTcpSocket *> m_sockets;
QTcpServer *server;
Userinterface userInterface;
QString nickname;
QString port;
QString ip;
};
#endif // TCPCLIENT_H