问题
I am working on an app that uses peer-to-peer communication between Android devices. It receives and delivers JSON data and the data never goes through the server ever. The server is only used to keep track of user IDs, login times, IP changes, and other stuff. This app will use sockets for communication.
Requirements
- JSON data goes directly to an Android device from another Android device without going through server.
- The android devices can be connected to any kind network like 3G or Wi-Fi (here I assume I have to use NAT).
- Server is used to keep track of IP changes of the Android devices as they may be connected to any kind of network.
Challenges
The main problems I am facing are:
- I don't know how to connect two devices if they are behind a Wi-Fi network.
- What approach I can use if I am going to use P2P for delivering JSON data.
Update
For this I have to use hole punching. The idea I got is that no one can connect to a device from the outside. It must start communication from inside the device. So if A request server S for address of B, then server gives the address of B to A and vice versa. Now what? What occurs next?
Any suggestion would be greatly appreciated.
来源:https://stackoverflow.com/questions/35908121/peer-to-peer-communication-holepunching-android