receive the data from the source and * turn the data back

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of BroadcastReceive by mbed official

Revision:
0:28ba970b3e23
Child:
3:689f37688374
diff -r 000000000000 -r 28ba970b3e23 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Mar 01 16:23:51 2013 +0000
@@ -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);
+    }
+}