IPhone peer-to-peer Internet connection (behind cellular NAT) with 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 bi-directionally. Sometimes the iPhone makes a request to the server again when the server makes a request to the iPhone. The problem is that the iPhone is behind the NAT of the cellular network and it does not have a fixed ip: port, with each new connection the port changes.

I think I need to make the bidirectional socket SO_REUSEADDR / SO_REUSEPORT and make the connection permanent.

Two other solutions are an Apple Push notification and a lengthy survey, at the moment I need an answer for a P2P solution between the iPhone and the server.

Can you advise me what I should do, or provide me with a working code example where the iPhone can receive messages from a host located on the Internet?

+4
source share
2 answers

It is unfortunate that Java is not supported on the iPhone, because the JXTA infrastructure would solve your problem easily.

What you are looking for is TURN , as a P2P implementation. Iphone needs to initiate a connection to the server in order to punch a hole in NAT, and yes, it needs to be supported (even if you are exploring more complex implementations such as STUNT to bypass NAT).

With TURN, the server must transfer messages between IPhones, STUNT, messages are transmitted directly between devices, but it is rather difficult to implement them correctly.

0
source

I read a lot about these things, and I understand that XMPP is the solution for you. use an open XMPP server (e.g. openfire) and XMPPframework (ios module).

0
source

Source: https://habr.com/ru/post/1340649/


All Articles