-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathudp-test.cpp
38 lines (33 loc) · 919 Bytes
/
udp-test.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
31
32
33
34
35
36
37
38
// run `nc -ulp 1337` on 192.168.1.102 and you'll receive 'hi', then it'll close
UDP udp;
USBSerial serial;
byte ip[] = {192,168,1,255};
int i = 0;
void setup() {
serial.begin(9600);
pinMode(D7, OUTPUT);
}
void loop() {
if (!udp.begin(1337)) {
serial.write("begin() failed\r\n");
} else {
serial.write("begin() succeeded\r\n");
if (!udp.beginPacket(ip, 50011)) {
serial.write("beginPacket() failed\r\n");
} else {
serial.write("beginPacket() succeeded\r\n");
udp.write("hi\n");
serial.write("wrote hi\r\n");
if (!udp.endPacket()) {
serial.write("endPacket() failed\r\n");
} else {
serial.write("endPacket() succeeded\r\n");
}
}
}
digitalWrite(D7,HIGH);
delay(500);
digitalWrite(D7,LOW);
delay(1000);
udp.stop();
}