iPhone(位于蜂窝 NAT 后面)与服务器的点对点互联网连接

发布于 2024-10-18 05:05:20 字数 330 浏览 1 评论 0原文

我有一部使用 3G 蜂窝网络的 iPhone 和一台互联网服务器,我希望它们能够双向交换消息。有时 iPhone 向服务器发出请求,有时服务器向 iPhone 发出请求。问题是 iPhone 位于蜂窝网络的 NAT 后面,并且它没有固定的 ip:port ,在每个新连接上端口都会发生变化。

我想我必须创建一个双向套接字 SO_REUSEADDR/SO_REUSEPORT 并使连接持久。

另外两个解决方案是Apple的推送通知和长轮询,现在我需要iPhone和服务器之间的P2P解决方案的答案。

您能否建议我该怎么做,或者为我提供一个工作示例代码,让 iPhone 可以从互联网上的主机接收消息?

I have an iPhone on a 3G cellular network and a server on the internet and I want them to be able to exchange messages bidirectionally. Sometimes the iPhone makes a request to the Server some other times the Server makes a request to the iPhone. Problem is that the iPhone is behind the NAT of the cellular network and it doesn't have a fixed ip:port , on every new connection the port changes.

I think I have to make a bidirectional socket SO_REUSEADDR/SO_REUSEPORT and make the connection persistent.

The other two solutions are Apple's Push notification and long polling, for now I need an answer for the P2P solution between the iPhone and the Server.

Can you advise me on what I have to do or provide me a working example code where an iPhone can receive messages from a host that is on the internet?

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

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

发布评论

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

评论(2

罗罗贝儿 2024-10-25 05:05:20

遗憾的是,iPhone 上不支持 Java,因为 JXTA 框架可以轻松解决您的问题。

您正在寻找的是类似于 P2P 实施的 TURN 。 Iphone 必须启动与服务器的连接以打通 NAT 中的漏洞,是的,它必须保持活动状态(即使您研究更复杂的实现,例如 STUNT 用于 NAT 穿越)。

使用TURN时,服务器必须在IPhone之间传输消息,使用STUNT时,消息直接在设备之间传输,但正确实现起来相当复杂。

It is a pity that Java is not supported on the iPhone, because the JXTA framework would have solved your issue easily.

What you are looking for is a TURN like implementation of P2P. The Iphone has to initiate the connection to the server to punch the hole in the NAT and yes, it has to be kept alive (even if you investigate more sophisticated implementations like STUNT for NAT traversal).

With TURN, the server has to transmit messages between IPhones, with STUNT, messages are transferred directly between devices, but it is quite complicated to implement properly.

单身狗的梦 2024-10-25 05:05:20

我已经做了很多关于这些事情的阅读,我的理解是 XMPP 是适合您的解决方案。使用开源 XMPP 服务器(如 openfire)和 XMPPframework(ios 模块)。

i've been doing a lot of reading up on these things and my understanding is that XMPP is the solution for you. use an open source XMPP server (like openfire) and XMPPframework (an ios module).

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