Programming Android Sockets for a Router

Hi guys, I have a question or problem. I am trying to make a p2p connection between two Android phones. Every phone connects to my server, and I get their private (192.168.1.1) and open (76.123.288.22) IP addresses and along with the ports that they connect to my server. I send a response when the phone connects to the server to open a server socket with a specific port. I also send a public IP and an open socket port to another phone, but it does not connect. I read several threads here that it is not possible to make a p2p connection if both phones or computers are behind two different routers. My question is, is this true, and if so, how do LogMeIn or other p2p applications work on different routers? Is this a programming error or network architecture does not allow?

+7
source share
2 answers

There are several ways to achieve this - STUN , TURN , ICE , to name a few. You can read about each of them, and software such as skype, gtalk, etc., uses these methods among others.

But the basic concept that needs to be understood here is

  • You need an ip available to the public so you can connect to it. If it is located behind a router on a private network, you need port forwarding on the router, that is, you need to add a rule to this router to forward traffic received on a specific port to your server behind the router. To a certain extent, the above methods achieve this implicitly or by involving an external third-party server.

  • You need to allow incoming connections on the machine to which it is first connected. Typically, Windows or linux firewalls block all incoming connections unless an exception is added. This will probably be needed for both of your nodes.

In the last part, I do not program on android, so I'm not sure that it allows you to add rules for incoming connections, etc. But I know that gtalk has a client for android, and gtalk uses XMPP, which internally can use any of those methods that I indicated above. Therefore, there is no reason to believe why this cannot be done for an Android phone.

Adding a few more useful links:

libjingle is a google open source library that can be used to write p2p applications, including text, audio and video.

It seems that it was compiled for android, but here

+5
source

"My question is, is this true, and if so, how does LogMeIn or other p2p applications work on different routers?"

The difference here is that the connections for both machines continue through the central server - they do not connect directly to each other (except in special cases).

What you want to do does not work, by design. If TCP could do this, then anyone could contact anyone.

You need your central server to transfer traffic from one phone to the connection made by another phone to the server.

Either set up a VPN or use Google Chrome for the phone (the name can be changed), which is a means of sending small messages to phones, regardless of the network topology.

0
source

All Articles