Android TCP communication over the internet(not LA

2019-05-28 09:10发布

问题:

I'm creating an app to establish communication between two android mobiles through the internet using TCP sockets. So, I'll primarily be using ip addresses of the two mobiles with my fancy app port no.

Is this possible? To create custom TCP ports and communicate over the internet like in a LAN?

So far i'm able to successfully communicate between two emulators in a LAN . But it's not possible to do the same thorugh the internet in case of emultors cos usually the host machine is behind a router that allows only data to the port 8080 or 80 i'm not sure. Of course there are port forwarding that can be done, but i don't wanna get dirty with that.
so,
Does emulator connection in LAN guarantee mobile connection in the internet? cos in case of mobile with direct net connectivity there is only single ip address(no private and external ip) and no router to bar the trafffic.

回答1:

Have You heard about hole punching technique. Read about this - maybe it will be helpfull.link This is how skype works I think.The technique requires yet another node in communication - a server which is accessible by both clients, and which helps to make direct connections between two clients even if one of the client is behind a NAT.



回答2:

I'm 99.8% sure that you will not be able to do this on mobile networks. If I recall correctly, each cell tower has its own IP, and each device connected to it has a private, internal IP. However, I'm sure you could get this to work on Wifi.