Simple code for comunication via TCP between the mbed and PC.

Dependencies:   EthernetInterface SimpleSocket mbed-rtos mbed

Fork of SimpleSocketExamples by Hiroshi Yamaguchi

examples/udpreceiver.cpp

Committer:
numeral369
Date:
2014-12-17
Revision:
1:016774025718
Parent:
0:6dc3cfd058c6

File content as of revision 1:016774025718:

#include "SimpleSocket.h"

void udpreceiver() {
    DatagramSocket datagram(7777);
    datagram.setTimeout(1.0);
    Endpoint buddy;
    while (true) {
        if (datagram.receive(buddy) > 0) {
            char *ip = buddy.get_address();
            int port = buddy.get_port();
            char buf[80] = {};
            int len = datagram.read(buf, sizeof(buf) - 1);
            printf("received from %s:%d %s", ip, port, buf);
        }
    }
}