forked from mrhornsby/spark-core-mdns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdns.ino
64 lines (44 loc) · 1.19 KB
/
mdns.ino
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "MDNS/MDNS.h"
#include <vector>
#define HTTP_PORT 80
#define ALT_HTTP_PORT 8080
MDNS mdns;
TCPServer server = TCPServer(HTTP_PORT);
TCPServer altServer = TCPServer(ALT_HTTP_PORT);
void setup() {
server.begin();
altServer.begin();
std::vector<String> subServices;
subServices.push_back("printer");
bool success = mdns.setHostname("core-1");
if (success) {
success = mdns.addService("tcp", "http", HTTP_PORT, "Core 1", subServices);
}
mdns.addTXTEntry("normal");
if (success) {
success = mdns.addService("tcp", "http", ALT_HTTP_PORT, "Core alt");
}
mdns.addTXTEntry("alt");
if (success) {
success = mdns.begin();
}
}
void loop() {
mdns.processQueries();
TCPClient client = server.available();
if (client){
while (client.read() != -1);
client.write("HTTP/1.1 200 Ok\n\n<html><body><h1>Ok!</h1></body></html>\n\n");
client.flush();
delay(5);
client.stop();
}
TCPClient altClient = altServer.available();
if (altClient){
while (altClient.read() != -1);
altClient.write("HTTP/1.1 200 Ok\n\n<html><body><h1>Alternative port ok!</h1></body></html>\n\n");
altClient.flush();
delay(5);
altClient.stop();
}
}