在两部 Android 手机之间持续发送和接收数据的最快方式

发布于 2024-09-25 23:33:22 字数 132 浏览 0 评论 0原文

在两部 Android 手机之间持续发送和接收数据的最快方法是什么?

例如长、纬度、IM 或只是一些数字。

不适用于始终在线的连接或推送服务。该应用程序正在前台运行并等待双方的数据。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

全部不再 2024-10-02 23:33:22

我不是 Android 方面的专家,但如果 Android 平台上提供此类连接,您可以尝试通过 UDP 进行一些操作。

假设您的设备有私有 ipv4 地址,您将需要一个中央服务器(具有公共 ipv4 地址)来告诉它们如何通过 NAT 转换其私有地址。

该转换后的地址必须传输到可以开始通过 UDP 与发起设备通信的其他设备。如果没有太多通信,请确保启用 UDP 连接上的任何“保持活动”选项。

如果所有设备都有公共 IP 地址(我对此表示怀疑),那么您只需同意端口并打开 UDP 连接即可。同行只需交换他们的公共地址即可。

如果所有设备都有 IPv6 地址,那么您也可以按原样使用这些地址(一旦您同意端口)。同行也只需要先交换它们即可。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文