Android Tutorial No-IP Android client - Access your device over the internet

Status
Not open for further replies.
SS-2013-02-21_16.08.18.png


The following solution allows you to access your Android device over the internet. The device must be connected to a local network (with internet access) and configured properly.

You can use this solution together with HttpServer library to turn an unused Android device to a Http Server.

There are several challenges which we must overcome to get it working:
1. The local network public IP (wan IP) is dynamic. It changes from time to time.
2. The router needs to be configured to forward incoming connections to the device.

The DynamicIp service module overcomes the first challenge.
It is a simple No-IP updater client: Free Dynamic DNS - Managed DNS - Managed Email - Domain Registration - No-IP
No-IP is a free service that allows you to map a no-ip subdomain to your IP address. The updater is responsible for updating the IP. Every 30 minutes it checks whether the public IP has changed with another free web service: ExIp.Org - Home
If the IP address has changed then it updates the No-IP web service.

In order to use this service you should create a free account and pass the host, username and password to DynamicIp service:
B4X:
If FirstTime Then
   Dim ni As NoIpValues
   ni.Host = "zzzzz.no-ip.org"
   ni.Username = "yyyyy"
   ni.Password = "xxxxx"
   CallSubDelayed2(DynamicIp, "Start", ni)
End If

You only need to start it once. It uses an internal timer to periodically check the IP address.

The second task requires you to configure your router:
1. The router should assign your device (based on the MAC address) a static local IP address.
2. The router should forward incoming connections on the relevant port to the device IP address.

There are many online tutorials about these tasks (such as: Free Help Forwarding Ports - PortForward.com).

Note that you can also use raw sockets (Network library) though it will be simpler to use HttpServer in most cases.

The DynamicIp service is attached. It depends on HttpUtils2 code modules (which depends on Http and StringUtils libraries).
 

Attachments

  • DynamicIp.bas
    2 KB · Views: 2,868

Tim_Pennard

Member
Licensed User
Hi, I'm also trying to access my Android device (which is running the HttpServer library) over the internet. I see there are helpful comments here back in 2014 that exIP.org is out of service and suggesting an alternative; and also techknight's update above. Does anyone have experience of implementing this more recently who can advise on the services available now and/or any code samples?
 

Tim_Pennard

Member
Licensed User
Hi,
Thank you for your help Erel.

I looked at whatismipaddress although I couldn't see how I can access it to update the dynamic external IP via the DynnamicIp service in b4a.

As a test, should it work without that step (just use the dynamic IP for a short period - if it doesn't change)? So far, I can't get that step to work.
I have forwarded a port to the device IP that is running the server code (192.168.0.45) TCP 5555 and UDP 5555 in the router.
The device has a static IP.
If I type my external IP address into a web browser http://90.xxx.xx.xxx:5555 I get a message that the site can't be reached.
I currently have a variable in my application called SERVER_IP_ADDRESS that I set to the device ID when using my internal network.
SERVER_IP_ADDRESS = "http://192.168.0.45:5555" For example I can then call "job1.download(SERVER_IP_ADDRESS & sb)"
Do I need to change this or does it stay as the device IP?

Sorry for the novice questions and thanks for any help.
Tim
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
As a test, should it work without that step (just use the dynamic IP for a short period - if it doesn't change)?
Yes.

So far, I can't get that step to work.
It is not so simple. This is why I suggested to start like this.

Please start a new thread for further discussion.
 
Status
Not open for further replies.
Top