P2P how do I shot web? (how does it work)

I’ve been curious about how P2P communications work; I’d like to try implementing them into my projects. How do P2P applications know who to connect to; they span multiple ports and ip addresses. Do they just send out pings every so often and wait for responses? How do they do it without trackers now?