Example reception of multicast messages (broken)

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of MulticastReceive 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:f3060367c0f9
Parent:
0:c30ede6e9b30

File content as of revision 1:f3060367c0f9:

#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 server;
    server.bind(MCAST_PORT);
    if (server.join_multicast_group(MCAST_GRP) != 0) {
        printf("Error joining the multicast group\n");
        while (true) {}
    }
    
    Endpoint client;
    char buffer[256];
    while (true) {
        printf("\nWait for packet...\n");
        int n = server.receiveFrom(client, buffer, sizeof(buffer));
        
        printf("Packet from \"%s\": %s\n", client.get_address(), buffer);
    }
}