]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/helloworld/multicast_receive/main.cpp
Merge commit '28203e909e83b1ac6becb45a3eadae23b190df32' into master-core-pull
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / tests / net / helloworld / multicast_receive / main.cpp
1 #include "mbed.h"
2 #include "EthernetInterface.h"
3
4 const char* MCAST_GRP = "224.1.1.1";
5 const int MCAST_PORT = 5007;
6
7 int main() {
8 EthernetInterface eth;
9 eth.init(); //Use DHCP
10 eth.connect();
11
12 UDPSocket server;
13 server.bind(MCAST_PORT);
14 if (server.join_multicast_group(MCAST_GRP) != 0) {
15 printf("Error joining the multicast group\n");
16 while (true) {}
17 }
18
19 Endpoint client;
20 char buffer[256];
21 while (true) {
22 printf("\nWait for packet...\n");
23 int n = server.receiveFrom(client, buffer, sizeof(buffer));
24
25 printf("Packet from \"%s\": %s\n", client.get_address(), buffer);
26 }
27 }
Imprint / Impressum