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

Dependencies:   EthernetInterface SimpleSocket mbed-rtos mbed

Fork of SimpleSocketExamples by Hiroshi Yamaguchi

examples/multicast.cpp

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

File content as of revision 1:016774025718:

#include "SimpleSocket.h"

void multicast() {
    Endpoint multicast;
    multicast.set_address("239.192.1.100", 50000);
    DatagramSocket datagram(multicast);
    
    while (true) {
        Endpoint host;
        datagram.setTimeout(1 + (rand() % 5) / 3.0);
        if (datagram.receive(host) > 0) {
            int value;
            datagram.scanf("%d", &value);
            char *ip = host.get_address();
            printf("received from %s:%d %d\n", ip, host.get_port(), value);
        } else {
            char* message = "12345!";
            datagram.printf(message);
            datagram.send(multicast);
            printf("sent: %s\n", message);
            wait(1);
        }
    }
}