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 1:129986b437b1, committed 2012-07-26
- Comitter:
- emilmont
- Date:
- Thu Jul 26 16:35:11 2012 +0000
- Parent:
- 0:97e3476ef63e
- Child:
- 2:3307c4a7c499
- Commit message:
- First implementation
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Thu Jul 26 16:35:11 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/EthernetInterface/#b7a3766f6253
--- a/main.cpp Thu Jul 26 16:31:15 2012 +0000 +++ b/main.cpp Thu Jul 26 16:35:11 2012 +0000 @@ -1,1 +1,31 @@ #include "mbed.h" +#include "EthernetInterface.h" + +const char* ECHO_SERVER_ADDRESS = "10.2.131.73"; +const int ECHO_PORT = 7; + +int main() { + EthernetInterface eth; + eth.init(); //Use DHCP + eth.connect(); + + UDPSocket sock; + sock.init(); + + 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); + + char in_buffer[256]; + UDPPacket in_packet(in_buffer, sizeof(in_buffer)); + int n = sock.receiveFrom(in_packet); + + in_buffer[n] = '\0'; + printf("%s\n", in_buffer); + + sock.close(); + + eth.disconnect(); + while(1) {} +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Thu Jul 26 16:35:11 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#4238c328365e