9

I want to connect 2 or more Android devices with p2p connection. As I understand I may use Wi-Fi Direct under one wifi network https://developer.android.com/guide/topics/connectivity/wifip2p.html

But I want to connect Android clients located in different places but possibly with the one IP (vpn or something). How can I do that?

Here is my algorithm

Client_1 register its name and current IP on Server
Client_2 register its name and current IP on Server
Client_1 request registred IP from Server by Client_2 name
Client_2 request registred IP from Server by Client_1 name
Client_1 send message directly to Client_2 IP

This algorithm will not work if Client_1 and Client_2 has the same IP. Or if client is behind NAT.

Is there a ready to use library to connect 2 or more Android devices in such way?

ugur
  • 3,604
  • 3
  • 26
  • 57
user1312837
  • 1,268
  • 1
  • 11
  • 29
  • Your Android devices on the public Internet will always be behind and IPv4 NAT. That means each device would need to initiate the conversation, so you have the chicken-and-egg problem. You will either need an external server with a public IPv4 address to which both can connect, or you can use global IPv6 addresses if they have them. – Ron Maupin Aug 08 '16 at 14:12
  • SIP communication you can use. Install one sip server and user sip client applications like sipdroid, csipsimple etc. – Shiv Buyya Aug 13 '16 at 10:37

2 Answers2

1

You can use Fixed Ip Simcards if you want to do a setup for your personal purpose. Another option is to convert your android phone local private ip into public ip , this can be done via Update No-IP app , this app will give you a direct link to communicate with public ip you have.

I hope my answer would be somewhat helpful to you.

0

Your best bet would be to look into NAT traversal on cellular connections. There are several threads on Stack Overflow that discuss this for example UPnP NAT Traversal for 3G/4G Wireless Data Connection on Android and Android: NAT Traversal?

To sum things up the easiest solution would be to look into using STUN to determine if your application/device is NATed and then using TURN or ICE to try to establish a (not necessarily direct) connection between your devices using NAT traversal. There exist multiple libraries that implement these protocols/methods for example http://www.pjsip.org/ which has Android support and has a pretty good documentation including sample applications for all mentioned techniques.

KarlKode
  • 64
  • 4