Example reception of multicast messages (broken)

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of MulticastReceive by Emilio Monti

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003 
00004 const char* MCAST_GRP = "224.1.1.1";
00005 const int MCAST_PORT = 5007;
00006 
00007 int main() {
00008     EthernetInterface eth;
00009     eth.init(); //Use DHCP
00010     eth.connect();
00011     
00012     UDPSocket server;
00013     server.bind(MCAST_PORT);
00014     if (server.join_multicast_group(MCAST_GRP) != 0) {
00015         printf("Error joining the multicast group\n");
00016         while (true) {}
00017     }
00018     
00019     Endpoint client;
00020     char buffer[256];
00021     while (true) {
00022         printf("\nWait for packet...\n");
00023         int n = server.receiveFrom(client, buffer, sizeof(buffer));
00024         
00025         printf("Packet from \"%s\": %s\n", client.get_address(), buffer);
00026     }
00027 }