Back in the IPv4 days, people simply used broadcast packets check if there are any server available in the network as described in this answer. But in the IPv6 protocol they've dropped broadcast support. There is still multicast support available but how can/should I use it?
|
With broadcast the client sends a message to everybody on the network and all the servers reply. With multicast you define a multicast group address and all the servers subscribe to it. The client then sends a message to the group, the servers that have subscribed receive it and reply. Multicast is for when one sender wants to send to a group of receivers, like when a game client wants to send to a (potential) group of servers. Multicast addresses are special addresses where the system knows to treat them differently. The receiver tells the system that it wants to receive messages sent to a particular group, and the sender sends a message to the group address. On a LAN this just works. Across LANs you need multicast routing which isn't implemented on mostnetworks. But broadcast wouldn't work across LANs either. Using multicast makes sure that only the systems on the network that care about getting the message will receive it. How you implement this depends on the programming language etc. The structure of an IPv6 multicast address is as follows:
Together this means that you'll use an address starting with Multicast addresses are assigned by IANA. RFC3307 defines how to do it (the criteria is Expert Review, so it's not necessary to write an RFC on what you are doing or anything like that). In this answer I'll use the multicast address You don't have to have root access to use multicast. The following Python3.3 examples can be run with a normal user account: The server (listening on the multicast address):
And the client (sending to the multicast group and listening for the replies):
I used Python 3.3 because older versions don't have PS: using an existing library or framework for service discovery as suggested in another answer is a good idea. It will use multicast under the hood but save you from having to design and implement your own protocol. |
|||||||||||
|
|
There are protocols for service discovery which modern applications should use instead of broadcast or home-spun multicast solutions, whether you're on IPv4 or IPv6. Apple pushes mDNS/DNS-SD and Microsoft pushes UPnP. Both accomplish the same goals for simple service discovery, while UPnP offers many additional features. There are freely available libraries for both of those APIs for a multiple platforms. The relevant OSes include native support. Linux offers support via semi-standard system components installed by default on most distros. Note that UPnP can also be used for firewall configuration and hence may be the better choice for games that plan on having Internet play, although you can't rely on or require UPnP firewall control since many users don't have compatible routers or turn the feature off out of paranoia. |
||||
|
|