discovery of peer in p2p network
I'm currently implementing a p2p network in java for a chat application. However, I don't know how to discover online peers. Each peer will join the network with 2 attributes which are a username provided by user and the ip address they have. First of all, ip addresses are mostly dynamic, and users should be able to join the network from anywhere in the world. So, my question is how can I discover online peers, since I don't know their ip addresses?
Actually I'm not very sure how p2p networks work and how they are created. I implemented a peer object, and some threads for multiple communication. However, I don't know how to create protocols for communication, as far as I know JXTA has already created a protocol to deal with some peer discovery and message transfer. I'll be glad if anyone explain me how can I take advantage of jxta and what are the useful classes for me?