Hiroshi Yamaguchi / Mbed 2 deprecated SimpleSocketExamples

Dependencies:   EthernetInterface SimpleSocket mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers udpreceiver.cpp Source File

udpreceiver.cpp

00001 #include "SimpleSocket.h"
00002 
00003 void udpreceiver() {
00004     DatagramSocket datagram(7777);
00005     datagram.setTimeout(1.0);
00006     Endpoint buddy;
00007     while (true) {
00008         if (datagram.receive(buddy) > 0) {
00009             char *ip = buddy.get_address();
00010             int port = buddy.get_port();
00011             char buf[80] = {};
00012             int len = datagram.read(buf, sizeof(buf) - 1);
00013             printf("received from %s:%d %s", ip, port, buf);
00014         }
00015     }
00016 }