Trying to get friendly peers

time to read 2 min | 255 words

I am spending way too much time on this stupid feature, so I might as well ask for help. The situation is simple, I am trying to rewrite the DHT implementation to configure itself dynamically and on the fly. That requires each DHT node to be able to publish its presence on the network.

It looks simple, all you have to do is a UDP multicast over the network and then the real complexity starts (how to negotiate which node does what). The problem is that I can't get it to work in a way that would allow two nodes to run on the same machine.

Now, I am pretty sure that I am missing something huge here, but this is pretty much my first foray into the world of UDP, and most of my knowledge is theoretical. What I am trying to do is to multicast a "hello, I am here" message, which can be picked up by any listening node on the network, including nodes that are running on the current machine.

This is where I am running into the problem, I can't figure out how to get two apps listening to the same port, or, how to send the multicast message to multiple ports.

Note that I am using UDP here because it is the thing that should gives me this facility with the least dependencies possible. I tried using System.Net.PeerToPeer, but I wasn't able to get it to give me a list of peers and join notifications.

Any ideas?