![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
make the mbed take the role of broadcasting
Dependencies: EthernetInterface mbed-rtos mbed
Fork of BroadcastSend by
Diff: main.cpp
- Revision:
- 3:2d6cf1043ca6
- Parent:
- 0:e18c3e98ed3d
--- a/main.cpp Wed May 14 15:36:56 2014 +0000 +++ b/main.cpp Thu Oct 30 17:08:27 2014 +0000 @@ -1,25 +1,31 @@ +/********************************************************** +*file:udp broadcast +*Creator:JacobShi +*Time:2014/10/30 +* Description:make the mbed take the role of broadcasting + *********************************************************/ + #include "mbed.h" #include "EthernetInterface.h" - -const int BROADCAST_PORT = 58083; +const int BROADCAST_PORT = 8080; +char data_buffer[100]; int main() { EthernetInterface eth; eth.init(); //Use DHCP eth.connect(); - + printf("%s\n",eth.getIPAddress() ); UDPSocket sock; sock.init(); sock.set_broadcasting(); - Endpoint broadcast; broadcast.set_address("255.255.255.255", BROADCAST_PORT); - - char out_buffer[] = "very important data"; - + sock.sendTo(broadcast, "Hello", sizeof("Hello")); + while (true) { - printf("Broadcasting...\n"); - sock.sendTo(broadcast, out_buffer, sizeof(out_buffer)); - Thread::wait(1000); + int n=sock.receiveFrom(broadcast,data_buffer,sizeof(data_buffer)); + data_buffer[n]='\0'; + printf("%s\n",data_buffer ); + } -} + } \ No newline at end of file