UDP Echo Server example

Dependencies:   EthernetInterface mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
mbedAustin
Date:
Tue May 05 20:08:42 2015 +0000
Parent:
6:76845960c8a2
Commit message:
added more verbose output for terminal

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 76845960c8a2 -r bd7f46b6fa23 main.cpp
--- a/main.cpp	Wed May 14 15:35:17 2014 +0000
+++ b/main.cpp	Tue May 05 20:08:42 2015 +0000
@@ -7,7 +7,7 @@
     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);
     }
 }