Most phones (meaning those running Android and iOS) can do this already. On iOS, it's called AirDrop[1] and on Android it's called Nearby Share[2].
Both work without an internet connection or centralized server.
1. https://www.lifewire.com/airdrop-with-without-wifi-connectio...
2. https://www.theverge.com/2020/8/4/21353020/android-nearby-sh...
There are other apps, like FireChat and Bridgefy, available in the app stores that handle actual P2P messaging.