Search code examples
javaandroidnetwork-programmingp2p

Android P2P connection on WAN


I successfully connected connecting 2 android Mobiles p2p using:

        //On server 
        public static String SERVERIP = "192.68.100.104";
        public static final int SERVERPORT = 8080;
        .
        .
        .
        //on Client
        Socket socket = new Socket(serverIP,SERVERPORT);

Now I need to connect Devices on WAN, So that the server can access by any Client who knows Server WAN address.
I get my IP by this link now how can I use this IP so that my server can be accessed from any part of world. Thanks


Solution

  • You are probably setting behind a router which hides your local IP address from the rest of the world (look for NAT for more info on this). Basically, the world only sees your YOUR_ROUTER_IP (the one you get from the link you posted), your router takes care of carrying all IP packets from the outside world to you and vice versa. You will need to change your router settings so that your local device gets the router ip address. This way you can access your server application from anywhere in the world by using simple socket operations. I hope this helps.