Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface mbed-rtos mbed
Fork of UDPSocket_HelloWorld by
main.cpp
- Committer:
- emilmont
- Date:
- 2012-08-01
- Revision:
- 7:dedf5dde9798
- Parent:
- 6:25aad2d88749
File content as of revision 7:dedf5dde9798:
#include "mbed.h"
#include "EthernetInterface.h"
int main() {
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
UDPSocket sock;
sock.init();
Endpoint nist;
nist.set_address("utcnist.colorado.edu", 37);
char out_buffer[] = "plop"; // Does not matter
sock.sendTo(nist, out_buffer, sizeof(out_buffer));
char in_buffer[4];
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, nist.get_address(), nist.get_port(), timeRes);
sock.close();
eth.disconnect();
while(1) {}
}
