Using Dynamic Hosting

For general Flowcode discussion that does not belong in the other sections.
Post Reply
chipfryer27
Valued Contributor
Posts: 1575
http://meble-kuchenne.info.pl
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 356 times
Been thanked: 560 times

Using Dynamic Hosting

Post by chipfryer27 »

Hi

This is a follow up to these two posts

viewtopic.php?p=19988#p19988

viewtopic.php?p=19603#p19603

In them we use Flowcode to interact with servers located either on your own LAN or over the internet. Whilst the charts and targets used in the examples can handle both IP addresses and Domain Names, e.g. 111.222.333.444 or www.abc123.com they may need extra steps to operate with Dynamic Hosting.

If you have a static IP address from your internet service provider, you can simply use your IP address from outside to reach your server. However not everyone has static addresses and may not wish to host on third-party sites.

If you have a dynamic IP address from your internet service provider then your external IP address is not fixed and can and will change. How often it changes is down to your provider but it isn't unusual to have it change every few days or if you reboot your router. With your IP address changing how can traffic reach you?

Dynamic Hosting services overcome this concern. You can think on these as a "middle-man" between your server with a changing IP address and traffic wishing to connect. When you sign up for service, and most offer free services with certain restrictions, they issue you with a unique domain name to use (you get a choice). They also provide a small program to run on your server (PC/Mac/linux/RPi etc) which will update them as to your current IP address. Depending on your router it may also support dynamic hosting, updating your provider automatically if your address changes thereby negating the need for running anything on your server. Now if someone tries to reach you via your domain name, your service provider knows to tell them your current IP address.

Lets just say you have a dynamic IP address of 111.222.333.444 and your Dynamic Hosting service has given you a domain name of abc123.ddns.com. When someone tries to reach you by entering abc123.ddns.com into their browser they first reach your hosting service and they then return your current IP address within their Headers. Your browser receives this information and then redirects your request to your actual IP address. When your IP address changes, say to 111.222.333.555 your server/router immediately updates your dynamic hosting service with this change and they will redirect all traffic to your new address.

Whilst all of this is handled automatically by your browser and appears seamless to you, you may need to include extra code in your Flowcharts to detect a redirect is required and action.

There are many providers to choose from with two popular choices being No-IP and DynDns and in my example I use a free service from No-IP.

In my example I have a script running on my server to return current date and time called update_time.php and I have a domain name issued by No-IP of abc123.ddns.net (just for example, that address is not real). My chart will then make a GET request to abc123.ddns.net/update_time.php which takes me to No-IP, who then return my actual IP address within their header. My chart will parse this return to look for redirect instructions and act.

When the chart issues my GET request, it subsequently looks for a reply from the server containing specific information and if the reply contains redirect instructions it will extract this information and act.

The request and subsequent return redirect from No-IP is as follows. Note that your provider may do things differently but will be along similar lines.

Request:
"GET /update_time.php?offset=0.0 HTTP/1.1\r\nHost: abc123.ddns.net\r\n\r\n"

Response
HTTP/1.1 302 Found\r\nDate: Wed, 04 Jun 2025 05:28:39 GMT\r\nServer: Apache\r\nLocation: http://12.34.56.78:8080/update_time.php ... ent-Length: 0\r\nContent-Type: text/html\r\n\r\n

You can see in the response that near the beginning we see 302 Found. This is the code for a tempoary redirect and lets us know that redirection is required. Using the Advanced String Functions component (found under storage) we check for this 302 Found within the string and if present act.

Next we look for the position of http:// which preceeds the redirect address and remove everything up to then. Our Rx string now looks like

http://12.34.56.78:8080/update_time.php ... ent-Length: 0\r\nContent-Type: text/html\r\n\r\n

Next we look for the position of our target script and remove everything from there to the end. Our Rx string now looks like

http://12.34.56.78:8080

We then remove the http:// leaving our target address

12.34.56.78:8080

We can see from the above that we now have an address of 12.34.56.78 and in this instance a port :8080 is also specified

We check if a new port is specified and if not we assign 12.34.56.78 as our new target address

If a new port is specified we then remove the port number and assign it before assigning 12.34.56.78 as new address.

With this new information we then reissue our GET request as

"GET /update_time.php?offset=0.0 HTTP/1.1\r\nHost: 12.34.56.78\r\n\r\n"

(Note that the new Port number is used in the Open Socket component properties within Flowcode and is not actually part of our GET).

Again, this is just an example but will hopefully allow you to create your own charts that can use Dynamic Hosting.

update_time_json_redirect.fcfx
(29.9 KiB) Downloaded 5 times

Regards

Post Reply