Simple code for comunication via TCP between the mbed and PC.
Dependencies: EthernetInterface SimpleSocket mbed-rtos mbed
Fork of SimpleSocketExamples by
examples/udpreceiver.cpp@1:016774025718, 2014-12-17 (annotated)
- Committer:
- numeral369
- Date:
- Wed Dec 17 16:06:00 2014 +0000
- Revision:
- 1:016774025718
- Parent:
- 0:6dc3cfd058c6
A simple code for comunication via TCP between the Mbed and a PC
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 | } |