UDP Socket Hello World with Ethernet
Dependencies: mbed mbed-rtos EthernetInterface
mbed 2 and mbed OS 5
This is an mbed 2 example. For an mbed-os example, please see:
[Repository '/teams/mbed-os-examples/code/mbed-os-example-sockets/docs/tip/' not found]
Revision 7:dedf5dde9798, committed 2012-08-01
- Comitter:
- emilmont
- Date:
- Wed Aug 01 13:36:14 2012 +0000
- Parent:
- 6:25aad2d88749
- Child:
- 8:1ce6f6a1ad5a
- Commit message:
- Remove redundant UDPPacket class
Changed in this revision
--- a/EthernetInterface.lib Thu Jul 26 15:15:33 2012 +0000 +++ b/EthernetInterface.lib Wed Aug 01 13:36:14 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 15:15:33 2012 +0000 +++ b/main.cpp Wed Aug 01 13:36:14 2012 +0000 @@ -9,17 +9,17 @@ UDPSocket sock; sock.init(); + Endpoint nist; + nist.set_address("utcnist.colorado.edu", 37); + char out_buffer[] = "plop"; // Does not matter - UDPPacket out_packet(out_buffer, sizeof(out_buffer)); - out_packet.set_address("utcnist.colorado.edu", 37); - sock.sendTo(out_packet); + sock.sendTo(nist, out_buffer, sizeof(out_buffer)); char in_buffer[4]; - UDPPacket in_packet(in_buffer, sizeof(in_buffer)); - int n = sock.receiveFrom(in_packet); + int n = sock.receiveFrom(nist, in_buffer, sizeof(in_buffer)); unsigned int timeRes = ntohl( *((unsigned int*)in_buffer)); - printf("Received %d bytes from server %s on port %d: %u seconds since 1/01/1900 00:00 GMT\n", n, in_packet.get_address(), in_packet.get_port(), timeRes); + printf("Received %d bytes from server %s on port %d: %u seconds since 1/01/1900 00:00 GMT\n", n, nist.get_address(), nist.get_port(), timeRes); sock.close();
--- a/mbed-rtos.lib Thu Jul 26 15:15:33 2012 +0000 +++ b/mbed-rtos.lib Wed Aug 01 13:36:14 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