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 SimpleSocket mbed-rtos mbed
examples/udpreceiver.cpp@0:6dc3cfd058c6, 2013-02-04 (annotated)
- Committer:
- yamaguch
- Date:
- Mon Feb 04 09:29:18 2013 +0000
- Revision:
- 0:6dc3cfd058c6
modified to use SimpleSocket/EthernetInterface
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| yamaguch | 0:6dc3cfd058c6 | 1 | #include "SimpleSocket.h" |
| yamaguch | 0:6dc3cfd058c6 | 2 | |
| yamaguch | 0:6dc3cfd058c6 | 3 | void udpreceiver() { |
| yamaguch | 0:6dc3cfd058c6 | 4 | DatagramSocket datagram(7777); |
| yamaguch | 0:6dc3cfd058c6 | 5 | datagram.setTimeout(1.0); |
| yamaguch | 0:6dc3cfd058c6 | 6 | Endpoint buddy; |
| yamaguch | 0:6dc3cfd058c6 | 7 | while (true) { |
| yamaguch | 0:6dc3cfd058c6 | 8 | if (datagram.receive(buddy) > 0) { |
| yamaguch | 0:6dc3cfd058c6 | 9 | char *ip = buddy.get_address(); |
| yamaguch | 0:6dc3cfd058c6 | 10 | int port = buddy.get_port(); |
| yamaguch | 0:6dc3cfd058c6 | 11 | char buf[80] = {}; |
| yamaguch | 0:6dc3cfd058c6 | 12 | int len = datagram.read(buf, sizeof(buf) - 1); |
| yamaguch | 0:6dc3cfd058c6 | 13 | printf("received from %s:%d %s", ip, port, buf); |
| yamaguch | 0:6dc3cfd058c6 | 14 | } |
| yamaguch | 0:6dc3cfd058c6 | 15 | } |
| yamaguch | 0:6dc3cfd058c6 | 16 | } |