开发者

iPhone (behind cellular NAT) peer-to-peer internet connection with a server

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'开发者_如何学Gos 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?


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.


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).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜