UDP Echo Server example

Dependencies:   EthernetInterface mbed-rtos mbed

Revision:
5:0d4087d2486d
Parent:
2:6b1012d93eb2
diff -r 9ba81097c238 -r 0d4087d2486d main.cpp
--- a/main.cpp	Tue Jun 04 16:09:30 2013 +0100
+++ b/main.cpp	Tue Feb 14 16:54:31 2017 +0000
@@ -1,13 +1,13 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
-
+ 
 #define ECHO_SERVER_PORT   7
-
+ 
 int main (void) {
     EthernetInterface eth;
     eth.init(); //Use DHCP
     eth.connect();
-    printf("IP Address is %s\n", eth.getIPAddress());
+    printf("\nServer IP Address is %s\n", eth.getIPAddress());
     
     UDPSocket server;
     server.bind(ECHO_SERVER_PORT);
@@ -15,10 +15,13 @@
     Endpoint client;
     char buffer[256];
     while (true) {
-        printf("\nWait for packet...\n");
+        printf("\nWaiting for UDP packet...\n");
         int n = server.receiveFrom(client, buffer, sizeof(buffer));
+        buffer[n] = '\0';
         
         printf("Received packet from: %s\n", client.get_address());
+        printf("Packet contents : '%s'\n",buffer);
+        printf("Sending Packet back to Client\n");
         server.sendTo(client, buffer, n);
     }
-}
+}
\ No newline at end of file