Example message broadcasting

Committer:
emilmont
Date:
Fri Mar 01 16:25:32 2013 +0000
Revision:
0:e18c3e98ed3d
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 0:e18c3e98ed3d 1 #include "mbed.h"
emilmont 0:e18c3e98ed3d 2 #include "EthernetInterface.h"
emilmont 0:e18c3e98ed3d 3
emilmont 0:e18c3e98ed3d 4 const int BROADCAST_PORT = 58083;
emilmont 0:e18c3e98ed3d 5
emilmont 0:e18c3e98ed3d 6 int main() {
emilmont 0:e18c3e98ed3d 7 EthernetInterface eth;
emilmont 0:e18c3e98ed3d 8 eth.init(); //Use DHCP
emilmont 0:e18c3e98ed3d 9 eth.connect();
emilmont 0:e18c3e98ed3d 10
emilmont 0:e18c3e98ed3d 11 UDPSocket sock;
emilmont 0:e18c3e98ed3d 12 sock.init();
emilmont 0:e18c3e98ed3d 13 sock.set_broadcasting();
emilmont 0:e18c3e98ed3d 14
emilmont 0:e18c3e98ed3d 15 Endpoint broadcast;
emilmont 0:e18c3e98ed3d 16 broadcast.set_address("255.255.255.255", BROADCAST_PORT);
emilmont 0:e18c3e98ed3d 17
emilmont 0:e18c3e98ed3d 18 char out_buffer[] = "very important data";
emilmont 0:e18c3e98ed3d 19
emilmont 0:e18c3e98ed3d 20 while (true) {
emilmont 0:e18c3e98ed3d 21 printf("Broadcasting...\n");
emilmont 0:e18c3e98ed3d 22 sock.sendTo(broadcast, out_buffer, sizeof(out_buffer));
emilmont 0:e18c3e98ed3d 23 Thread::wait(1000);
emilmont 0:e18c3e98ed3d 24 }
emilmont 0:e18c3e98ed3d 25 }