开发者

Fastest way to constantly send and receive data between 2 Android phones

开发者 https://www.devze.com 2023-01-18 20:08 出处:网络
What is the fastest way to constantly send and receive data between 2 Android phones? e.g. long, lat, IM or just some number.

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 fo开发者_如何学Pythonr 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消