Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface SimpleSocket mbed-rtos mbed
multicast.cpp
00001 #include "SimpleSocket.h" 00002 00003 void multicast() { 00004 Endpoint multicast; 00005 multicast.set_address("239.192.1.100", 50000); 00006 DatagramSocket datagram(multicast); 00007 00008 while (true) { 00009 Endpoint host; 00010 datagram.setTimeout(1 + (rand() % 5) / 3.0); 00011 if (datagram.receive(host) > 0) { 00012 int value; 00013 datagram.scanf("%d", &value); 00014 char *ip = host.get_address(); 00015 printf("received from %s:%d %d\n", ip, host.get_port(), value); 00016 } else { 00017 char* message = "12345!"; 00018 datagram.printf(message); 00019 datagram.send(multicast); 00020 printf("sent: %s\n", message); 00021 wait(1); 00022 } 00023 } 00024 }
Generated on Mon Jul 18 2022 00:17:10 by
1.7.2