Example message broadcasting

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of BroadcastSend 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:
2:c6af880e0d98
Parent:
0:e18c3e98ed3d

File content as of revision 2:c6af880e0d98:

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

const int BROADCAST_PORT = 58083;

int main() {
    EthernetInterface eth;
    eth.init(); //Use DHCP
    eth.connect();
    
    UDPSocket sock;
    sock.init();
    sock.set_broadcasting();
    
    Endpoint broadcast;
    broadcast.set_address("255.255.255.255", BROADCAST_PORT);
    
    char out_buffer[] = "very important data";
    
    while (true) {
        printf("Broadcasting...\n");
        sock.sendTo(broadcast, out_buffer, sizeof(out_buffer));
        Thread::wait(1000);
    }
}