]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/tests/net/helloworld/multicast_receive/main.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[max/tmk_keyboard.git] / 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 }