iPhone(位于蜂窝 NAT 后面)与服务器的点对点互联网连接
我有一部使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
遗憾的是,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.
我已经做了很多关于这些事情的阅读,我的理解是 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).