once, the internet had(real) IP addresses…
on a perhaps overly object-level note, most modern phones RPi's etc will answer
hostname.local pings, so if they're /reliably/ right next to(read: same WiFi) each other you can get away with just opening a port; but it's true that if sometimes there is a whole internet between them, you need a server out on that internet somewhere for routing, and thus fuss about setting up ZeroTier or somesuch
(for a particularly polished mix of the two, check out
https://snapdrop.net/, which does still need a web server to ~ start ~ the devices talking to each other as a cost for working directly in the browser sandbox)