UDP Echo Client example

Dependencies:   EthernetInterface mbed-rtos mbed

Deprecated

This is an mbed 2 networking example. For mbed OS 5, the networking libraries have been revised to better support additional network stacks and thread safety here.

Files at this revision

API Documentation at this revision

Comitter:
mbedAustin
Date:
Tue May 05 20:08:56 2015 +0000
Parent:
7:9d51be7aab27
Child:
9:4f1a786624de
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
--- a/main.cpp	Wed May 14 15:33:15 2014 +0000
+++ b/main.cpp	Tue May 05 20:08:56 2015 +0000
@@ -1,13 +1,14 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
 
-const char* ECHO_SERVER_ADDRESS = "10.2.200.94";
+const char* ECHO_SERVER_ADDRESS = "192.168.2.2";
 const int ECHO_SERVER_PORT = 7;
 
 int main() {
     EthernetInterface eth;
     eth.init(); //Use DHCP
     eth.connect();
+    printf("\nClient IP Address is %s \n", eth.getIPAddress());
     
     UDPSocket sock;
     sock.init();
@@ -15,14 +16,15 @@
     Endpoint echo_server;
     echo_server.set_address(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
     
-    char out_buffer[] = "Hello World\n";
+    char out_buffer[] = "Hello World";
+    printf("Sending  message '%s' to server (%s)\n",out_buffer,ECHO_SERVER_ADDRESS);
     sock.sendTo(echo_server, out_buffer, sizeof(out_buffer));
     
     char in_buffer[256];
     int n = sock.receiveFrom(echo_server, in_buffer, sizeof(in_buffer));
     
     in_buffer[n] = '\0';
-    printf("%s\n", in_buffer);
+    printf("Received message from server: '%s'\n", in_buffer);
     
     sock.close();