This is a simple educational example of a multicast client and server, running under UNIX and Win32.
The server now can have an id from 0 to 3. Clients trace packets from all 4 servers. An arg has been added for server (first) for its id (0 to 3). Several servers (until 4, ids being 0, 1, 2 and 3) may be launched, clients track packets from all of them, correctly tracking lost packets.
To compile, use
mkdir build
cd build
cmake ..
cmake --build .
See https://developer.android.com/ndk/guides/cmake.html as a reference, but
basically it boils down to adding -DANDROID_NDK=<path> -DCMAKE_TOOLCHAIN_FILE=<path> -DANDROID_NATIVE_API_LEVEL=<API level you want>
to the cmake .. step above.
If there is no data coming through when client and server are on different
machines, the reason can be that IP routing is configured in a way that routes
multicast traffic to or expects multicast traffic from an interface the other
machine is not connected to (the sample programs in this repo do not use the
IP_MULTICAST_IF setsockopt() call yet as it's not cross-platform).
In this case, you have to add a static route to the client and/or server machine's
routing table indicating the interface for multicast traffic. The internet has
lots of examples.
