문제

What is the fastest way to constantly send and receive data between 2 Android phones?

e.g. long, lat, IM or just some number.

not for an always-on connection or push services. The app is running on foreground and waiting for data on both sides.

도움이 되었습니까?

해결책

I am not an expert with Android, but there is something you might try via UDP if such connections are available from the Android platform.

Assuming your devices have private ipv4 addresses, you would need a central server (with a public ipv4 address) which could tell them how their private address is being translated by their NAT.

This translated address would have to be transmitted to other devices which could start communicating with the initiating device via UDP. If there is not much communication, make sure you enable any 'keepalive' option on the UDP connections.

If all devices have public IP addresses (which I doubt), then you just need to agree on a port and open UDP connections. The peers just have to exchange their public address.

If all devices have IPv6 addresses, then you can use these as is too (once you agree on a port). Peers just need to exchange them first too.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top