forked from techtim/mdnsServicepp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.cpp
30 lines (24 loc) · 955 Bytes
/
example.cpp
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
#include "mdnsService.h"
int
main()
{
mdns::MdnsService service;
auto txts = mdns::TxtRecordArray{std::make_pair("mac", "13:13:13:13:13:13"),
std::make_pair("rand", "asdaood asdasdjsa;ldj alkdsjlsa djsalkdjsakld")};
service.start("_http._tcp.local.", "Hello", std::move(txts));
// DNS-SD discovery
service.discover();
// Find services with name "_http._tcp.local."
auto discovered = service.sendMdnsQuery("_http._tcp.local.");
for (const auto &res : discovered) {
std::cout << "MdnsQuery Result: " << mdns::ipv4_address_to_string(&res.ipv4) << " service=" << res.service
<< " hostname=" << res.hostname << " txt records: ";
for (const auto &txt : res.txt_records)
std::cout << txt.first << "=" << txt.second << ";";
std::cout << std::endl;
}
while (1) {
; // run for self discovery
}
exit(0);
}