Search code examples
androidsockets3g

Socket programming in android over 3g


I have managed to send information from my pc to my android phone via wifi, if they share the same network. Is it possible to send information from my pc to my phone in the same manner, if the phone is not connected to the same network i.e. if the phone is connected to 3g.

In that case, what ip address do I have to use? Is it a lot harder? Can someone tell/link me to some site regarding this?

thank you for answers


Solution

  • In this case, you need to locate Android phone. Your PC don't know his IP address.

    You can use DynDNS or similar service, to dynamically register your phone in DNS. Then use DynDNS client on PC to get phone's ip.

    Another way is where PC has known IP address. So, Android device can send a request to it, PC remember Android's IP and then use it when sending info to Android. This method has two drawbacks, PC can be behind a NAT (it need additional admin efforts), and it can have a dynamic IP.

    If you have a website, there is another way. Write a script (e.g. devreg.php), that will store client's IP in db or file, and another script (devfind.php), that will read IP from db/file and send it in response. So, Android will first send request to devreg.php, and it will save IP. Then PC will request devfind.php, and it will send Android's IP in response.