Allahjane
Allahjane

Reputation: 1978

Direct TCP/IP networking between two android devices over internet

Hey I am just a beginner at networking.

Is it possible to connect two android devices to each other using sockets over the Internet without using any intermediate dedicated server, Given that there are Nat routers in the wifi and GPRS/3G connections.

I heard that you need to send a outgoing message to other device first , then only NAT would allow that device to reply back to you. But when both device behind NAT how would the first message or packet reach to anyone of them?

EDIT : Observation-> When i query for location of my public IP address I get random places like other cities and sometimes other states!!! What's the matter? can anyone explain?

Upvotes: 0

Views: 4482

Answers (1)

Kristian Evensen
Kristian Evensen

Reputation: 1345

The overall design of such a solution involves the use of a third party server. In order for the clients to connect to each other, their public IP (i.e., the NATs IP) has to be known to the other party. When I had to something similar, I implemented STUN, which is part of the ICE technique for establishing peer-to-peer connections. STUN supports both TCP and UDP-traffic. If you want to understand STUN, you should also read about TURN.

Even though STUN requires the user of a third-party for clients to be able to connect directly, there are many public STUN servers available. Here is one of the lists a quick-google search turned up.

Upvotes: 1

Related Questions