This example shows you how to build a multicast UDP server. The basic structure of this server is similar to the Basic UDP Echo Server example and you should go and read about that first and have a good understanding of how everything fits together. This document will only cover the differences between the
Basic UDP Echo Server example and this example.
This example is shipped with all licensed versions of The Server Framework and it requires the core server framework libraries (see
here for licensing options). You can always download the latest version of this example from
here; and although you will need the correct libraries to be able to build it you can look at the example code and see how it works and perhaps get ideas from it. A compiled, unicode release, build of this example is available on request if you require it for performance analysis of the framework.
The
ServerMain.cpp
file for this example is very similar to the previous example. The only differences is that we accept a multicast group address on the command line and we join that multicast group once the server has started.
CSocketServer server(
address,
listenBacklog,
pool,
socketAllocator,
bufferAllocator,
connectionLimiter);
server.Start();
server.StartAcceptingConnections();
if (commandLine.HasMulticastAddress())
{
const CFullAddress groupAddress(
commandLine.MulticastAddress(),
commandLine.Port());
const CFullAddress interfaceAddress(
commandLine.Server(),
0);
server.JoinMulticastGroup(
groupAddress,
interfaceAddress);
}
CSecurityDescriptorAllowAll sd;
The server itself is the same but it will receieve data from either the address and port that it's listening on or the multicast group that it belongs to.