Skip to content

Commit 6f0b00d

Browse files
Add PeerDiscovery class for multicast peer discovery
1 parent d96c4ad commit 6f0b00d

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef PEER_DISCOVERY_HPP
2+
#define PEER_DISCOVERY_HPP
3+
#include <QObject>
4+
#include <QtTypes>
5+
#include <QtNetwork/QUdpSocket>
6+
#include <QStringLiteral>
7+
8+
namespace zclipboard::znetwork {
9+
class PeerDiscovery : public QObject {
10+
Q_OBJECT
11+
12+
public:
13+
explicit PeerDiscovery(quint16 port = 45454, QObject *parent = nullptr);
14+
15+
signals:
16+
void peerFound(const QString &ipAddress);
17+
18+
private slots:
19+
void broadcastHello();
20+
void handleIncomingMessage();
21+
void prepareDatagram();
22+
QString getLocalDeviceName() const;
23+
QString getLocalIPAddress() const;
24+
25+
private:
26+
QString broadcast_msg;
27+
QUdpSocket socket;
28+
QHostAddress multicastGroup;
29+
quint16 port;
30+
};
31+
} // namespace zclipboard::znetwork
32+
33+
#endif // PEER_DISCOVERY_HPP

0 commit comments

Comments
 (0)