iOS objective c socket p2p connection with peers behind NAT - ios

I have to implement socket communication in iOS (Objective-C) between two peers located behind NAT (in different networks). Are there any techniques allowing me to achieve this? Basically I 'm looking for some STUN, TURN implementation, that would allow me find out external IP/Port address.
Thanks in advance,
Leonid

Related

Which is the best protocal to use in peer to peer network

I am working on the project that is asking me to use peer to peer network because this project will be applied in the environment that don't have a server. So I need help on which protocal and C/C++ API I can use to perform this.
In order to perform peer-to-peer you have to handle NATs which means you must perform a NAT Transversal (NAT Punch). This is typically done using UDP and STUN. From the second link:
Here’s a parting “TL;DR” recap: For robust NAT traversal, you need the
following ingredients:
A UDP-based protocol to augment
Direct access to a socket in your program
A communication side channel with your peers
A couple of STUN servers
Even then you are not guaranteed success. It is a very complicated subject so i recommend reading the entire NAT Transversal article.

Is there any straight way to establish P2P UDP connection behind NAT in delphi?

I've been trying to establish a P2P connections for a couple of weeks. After writing some code and using Indy's components, I've realized that it can not access the peer that is behind the NAT. Furthermore, I've heard about STUN services that provide a client's remote and local IPs and ports. I should say I've already had the other UDP client (server) remote and local IPs, so how can I implement my code and program to work properly? Is there any extra component in Indy's library that I should use?
There is the Ares Galaxy P2P Project I know about some years ago.
There was a recent fork by Christian at https://github.com/CWBudde/AresGalaxy which tries to port it to more modern Delphi versions.
It is a work in progress, but perhaps you may get some very good ideas in this source code, and ask Christian for help/ideas, especially about NAT transversal.

Decentralized Peer to Peer

I am interested in a peer 2 peer decentralized network , I have tried using libraries like pyp2p which required a rendezvous and the likes of https://github.com/macsnoeren/python-p2p-network , since i am not deep in the computer networks domain , I have several questions to ask :
Is it possible to solely communicate with a device only using IPV4 and An open port number without HTTP requests (DIRECT)? IS there a way to do this with socket programming and HTTP requests ? what libraries do you suggest that enable this functionality ?
Is port forwarding necessary for systems like this or can it be bypassed?
which library is best for developing decentralized peer to peer networks in the python language?
Is it possible to solely communicate with a device only using IPV4 and An open port number without HTTP requests (DIRECT)?
Yes, however one issue with direct peer-to-peer is the existence of NAT devices in many networks that block incoming connections.
IS there a way to do this with socket programming and HTTP requests ?
Yes, just open a listening socket on one end, and connect to it from the other.
what libraries do you suggest that enable this functionality ?
This is outside the scope of Stack Overflow questions, but you don't really need any library to create or use sockets. They're provided by the operating system and can be used using the standard library of most languages.
Is port forwarding necessary for systems like this or can it be bypassed?
If there are NAT devices on the path between the peers, you'd need some way of traversing that NAT. Port forwarding is one way of doing that. Look into UPnP and STUN if you want something more automatic.
which library is best for developing decentralized peer to peer networks in the python language?
I honestly don't know. You'll need to do your own research.

Send UDP from iPhone to iPhone via WAN

In my recent app I managed to send data (mostly audio) via UDP in my local network (WiFi) to other iPhone. And now I need to do this same but in WAN. Can You guys please point me in the right direction where to start? What I need to achieve this?
I'm using GCDAsyncSocket to manage sockets. I believe that I have to got server, where I can keep IP addresses of both devices.
Also, how can I connect to device behind NAT/Firewall? I'm guessing, that I need to have public IP address (scrapped for instance from http://checkip.dyndns.com/). And then do I need to traceroute? Or NSLookup? Or piggyback? Or do I need to use UDP hole punching?
I know it's a lot of question, but if you can just point me to the right technology, I would be very grateful.
To achieve a communication between two participants behind a NAT you could use Hole-Punching like you mentioned it. This is explained quite well here: http://en.wikipedia.org/wiki/UDP_hole_punching#Flow
Basically a Server with a Public IP and Port is used to share the Port-numbers of the iPhones.
But a NAT may use a different Port for every different IP the iPhone talks to. So if iPhone1 sends data to the server the NAT uses port X, but if iPhone1 wants to send data to a different IP the NAT may choose port Y. (See http://en.wikipedia.org/wiki/Network_address_translation#Symmetric_NAT)
To overcome this problem there is a protocol called UPnP and the lesser known NAT Port Mapping Protocol.
I am not well versed in UPnP but maybe someone else can provide some information on that.
The protocol NAT-PMP enables you to dynamically request an external port to be forwarded to your device. See http://en.wikipedia.org/wiki/NAT_Port_Mapping_Protocol, RFC 6886 .
This allows you to "predict" your external port and establish connections over NAT.

Comparison of P2P Technology

I have gone through various udp based P2P Technology like Stun . I have implemented UDP/TCP hole punching recently for implementing p2p.
I found there are other technology as for like ICE,UPnP and teredo
Can any body tell me what is the difference between these technology.
Which one is the latest technology/protocol used for P2P in recent year.
It will good If any can provide comparative analysis on various UDP based P2P protocols.
Any link or suggestion will appreciated.
ICE stands for Interactive Connectivity Establishment. It is a protocol for NAT traversal (i.e., punching holes) supported by the IETF. There has been several reviews and evolutions of the RFC. Some may find the specifications overkill in general or unclear when it comes to performing TCP NAT traversal.
UPnP is a technology helping local devices finding each other and start communicating automatically. It implements IGD for NAT traversal, which allows remote configuration of the NAT/Router (when possible) to redirect WAN traffic to the device. Unfortunately, this method is a huge threat to security, since any application could hijack NATs/routers to let any undesirable traffic come in.
Teredo is not really related to P2P or NAT traveral. If you have an IPv6 device A on a ipv4 LAN (for example), it won't be able to connect using ipv6 to a remote ipv6 enabled device B located on the WAN. Teredo allows A to communicate with B with ipv6 by transporting ipv6 over ipv4. Teredo is massaging the frictions between ipv4 and ipv6, so to speak.
None of these technologies is 'dominating' P2P for now. It is still a boiling environment.

Resources