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).