UDP Echo Server example

Dependencies:   EthernetInterface mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
emilmont
Date:
Thu Jul 26 15:08:23 2012 +0000
Parent:
0:3e54841149df
Child:
2:6b1012d93eb2
Commit message:
First implementation

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Thu Jul 26 15:08:23 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#b7a3766f6253
--- a/main.cpp	Thu Jul 26 15:00:24 2012 +0000
+++ b/main.cpp	Thu Jul 26 15:08:23 2012 +0000
@@ -1,1 +1,24 @@
 #include "mbed.h"
+#include "EthernetInterface.h"
+
+int main (void) {
+    EthernetInterface eth;
+    eth.init(); //Use DHCP
+    eth.connect();
+    printf("IP Address is %s\n", eth.getIPAddress());
+    
+    UDPSocket server;
+    server.bind(7);
+    
+    char buffer[256];
+    while (true) {
+        printf("\nWait for packet...\n");
+        
+        UDPPacket packet(buffer, sizeof(buffer));
+        int n = server.receiveFrom(packet);
+        
+        printf("Received packet from: %s\n", packet.get_address());
+        packet.set_data(buffer, n);
+        server.sendTo(packet);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Thu Jul 26 15:08:23 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#4238c328365e