Example message broadcasting

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of BroadcastSend 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 int BROADCAST_PORT = 58083;
00005 
00006 int main() {
00007     EthernetInterface eth;
00008     eth.init(); //Use DHCP
00009     eth.connect();
00010     
00011     UDPSocket sock;
00012     sock.init();
00013     sock.set_broadcasting();
00014     
00015     Endpoint broadcast;
00016     broadcast.set_address("255.255.255.255", BROADCAST_PORT);
00017     
00018     char out_buffer[] = "very important data";
00019     
00020     while (true) {
00021         printf("Broadcasting...\n");
00022         sock.sendTo(broadcast, out_buffer, sizeof(out_buffer));
00023         Thread::wait(1000);
00024     }
00025 }