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.

Revision:
2:3307c4a7c499
Parent:
1:129986b437b1
Child:
3:281043c08f67
--- a/main.cpp	Thu Jul 26 16:35:11 2012 +0000
+++ b/main.cpp	Wed Aug 01 13:10:43 2012 +0000
@@ -1,8 +1,8 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
 
-const char* ECHO_SERVER_ADDRESS = "10.2.131.73";
-const int ECHO_PORT = 7;
+const char* ECHO_SERVER_ADDRESS = "192.168.0.51";
+const int ECHO_SERVER_PORT = 7;
 
 int main() {
     EthernetInterface eth;
@@ -12,14 +12,14 @@
     UDPSocket sock;
     sock.init();
     
+    Endpoint echo_server;
+    echo_server.set_address(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
+    
     char out_buffer[] = "Hello World\n";
-    UDPPacket out_packet(out_buffer, sizeof(out_buffer));
-    out_packet.set_address(ECHO_SERVER_ADDRESS, ECHO_PORT);
-    sock.sendTo(out_packet);
+    sock.sendTo(echo_server, out_buffer, sizeof(out_buffer));
     
     char in_buffer[256];
-    UDPPacket in_packet(in_buffer, sizeof(in_buffer));
-    int n = sock.receiveFrom(in_packet);
+    int n = sock.receiveFrom(echo_server, in_buffer, sizeof(in_buffer));
     
     in_buffer[n] = '\0';
     printf("%s\n", in_buffer);