aboutsummaryrefslogtreecommitdiffstats
path: root/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/helloworld/broadcast_receive/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/helloworld/broadcast_receive/main.cpp')
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/helloworld/broadcast_receive/main.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/helloworld/broadcast_receive/main.cpp b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/helloworld/broadcast_receive/main.cpp
new file mode 100644
index 000000000..9cee34551
--- /dev/null
+++ b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/helloworld/broadcast_receive/main.cpp
@@ -0,0 +1,23 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+
+const int BROADCAST_PORT = 58083;
+
+int main() {
+ EthernetInterface eth;
+ eth.init(); //Use DHCP
+ eth.connect();
+
+ UDPSocket socket;
+ socket.bind(BROADCAST_PORT);
+ socket.set_broadcasting();
+
+ Endpoint broadcaster;
+ char buffer[256];
+ while (true) {
+ printf("\nWait for packet...\n");
+ int n = socket.receiveFrom(broadcaster, buffer, sizeof(buffer));
+ buffer[n] = '\0';
+ printf("Packet from \"%s\": %s\n", broadcaster.get_address(), buffer);
+ }
+}