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:
emilmont
Date:
Wed Aug 01 13:10:43 2012 +0000
Parent:
1:129986b437b1
Child:
3:281043c08f67
Commit message:
Remove redundant UDPPacket class

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
--- a/EthernetInterface.lib	Thu Jul 26 16:35:11 2012 +0000
+++ b/EthernetInterface.lib	Wed Aug 01 13:10:43 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#b7a3766f6253
+http://mbed.org/users/mbed_official/code/EthernetInterface/#0d9ae7845bfe
--- 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);
--- a/mbed-rtos.lib	Thu Jul 26 16:35:11 2012 +0000
+++ b/mbed-rtos.lib	Wed Aug 01 13:10:43 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#4238c328365e
+http://mbed.org/users/mbed_official/code/mbed-rtos/#70bd33086f56