Example multicasting of packets

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of MulticastSend by Emilio Monti

Legacy Warning

This is an mbed 2 example. To learn more about mbed OS 5, visit the docs.

main.cpp

Committer:
Kojto
Date:
2014-05-14
Revision:
1:547a9ffe63c8
Parent:
0:1d4435904b0b

File content as of revision 1:547a9ffe63c8:

#include "mbed.h"
#include "EthernetInterface.h"

const char* MCAST_GRP = "224.1.1.1";
const int MCAST_PORT = 5007;

int main() {
    EthernetInterface eth;
    eth.init(); //Use DHCP
    eth.connect();
    
    UDPSocket sock;
    sock.init();
    
    Endpoint multicast_group;
    multicast_group.set_address(MCAST_GRP, MCAST_PORT);
    
    char out_buffer[] = "very important data";
    while (true) {
        printf("Multicast to group: %s\n", MCAST_GRP);
        sock.sendTo(multicast_group, out_buffer, sizeof(out_buffer));
        Thread::wait(1000);
    }
}