UDP Echo Server example

Dependencies:   EthernetInterface mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Tue Feb 14 16:54:31 2017 +0000
Parent:
4:9ba81097c238
Commit message:
More verbose example. Update libraries.

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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/EthernetInterface.lib	Tue Jun 04 16:09:30 2013 +0100
+++ b/EthernetInterface.lib	Tue Feb 14 16:54:31 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/EthernetInterface/#183490eb1b4a
--- 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
--- a/mbed-rtos.lib	Tue Jun 04 16:09:30 2013 +0100
+++ b/mbed-rtos.lib	Tue Feb 14 16:54:31 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
--- a/mbed.bld	Tue Jun 04 16:09:30 2013 +0100
+++ b/mbed.bld	Tue Feb 14 16:54:31 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/ef9c61f8c49f
\ No newline at end of file