]> git.tdb.fi Git - xinema.git/blob - remote/source/discovery.cpp
Create an icon for the remote
[xinema.git] / remote / source / discovery.cpp
1 #include "discovery.h"
2
3 Discovery::Discovery():
4         broadcast_addr("ff02::1"),
5         port(34588)
6 {
7         socket.bind(QHostAddress::AnyIPv6);
8         connect(&socket, &QIODevice::readyRead, this, &Discovery::datagram_available);
9
10         connect(&timer, &QTimer::timeout, this, &Discovery::send_beacon);
11         timer.setInterval(5000);
12 }
13
14 void Discovery::start()
15 {
16         timer.start();
17         send_beacon();
18 }
19
20 void Discovery::stop()
21 {
22         timer.stop();
23 }
24
25 void Discovery::send_beacon()
26 {
27         socket.writeDatagram("xinema", 6, broadcast_addr, port);
28 }
29
30 void Discovery::datagram_available()
31 {
32         char rbuf[1024];
33         QHostAddress peer_addr;
34         socket.readDatagram(rbuf, sizeof(rbuf), &peer_addr, 0);
35         
36         emit server_discovered(peer_addr);
37 }