UDP Echo Client example
Dependencies: EthernetInterface mbed-rtos mbed
Fork of UDPEchoClient by
Diff: main.cpp
- Revision:
- 1:129986b437b1
- Parent:
- 0:97e3476ef63e
- Child:
- 2:3307c4a7c499
--- 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) {} +}