Network Connection

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Network Connection

Post by digitalstone » 24 Jun 2018 18:19

Hi,
I'm busy with this flow that automatically assigns an IP-address based on the situation, to determine when it's time to send out a certain signal within or outside the local network.
This flow would end with a simple "connection=true/false" and pass that back to the calling flow.
Until now i've used a check-loop with condition "Host Reachable" to perform a successful ping-signal to know if the connection is ready for datatransfer.
But sometimes this does not work, even on the 5th iteration when a connection has already been established.

Would it be better to use condition "Network Connection"?
Is that doing the same thing in the background or would that work way better?
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Network Connection

Post by Desmanto » 25 Jun 2018 17:26

Which device's IP address you wanna set? Is it the phone with automagic or other device?

You mean the flow reported the client is connected, but after returned back to the main flow, the data transfer fail? Seems like the unreliable connection, can be cause by weak signal, intermittent disconnect or probably the wifi AP/router problem. I've ever use Tplink WR-841HP, which always consistently delay the ARP package for about 20-30 seconds after inactivity. This make a simple ping command can work and fail at the same second, very frustating. There is no solution, until I get it RMA'ed, still the same. I eventually give up and never use that unreliable router anymore.

You should test for the stability of the connection first.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: Network Connection

Post by digitalstone » 25 Jun 2018 22:37

My router is an ASUS AC3200, it's a very stable router.
I've got the most up-to-date Merlin software flashed on it. It's definately not the router.

I've come to notice that the problem (very much) probably lies with something completely different: My VPN driver (dum-dum-duuuuum)
Since the new update (i think 2 updates ago) it has/creates problems while switching to WiFi/Mobile and from airplane mode. It also has random troubles connecting successfully to my local network.
FYI: I'm using Private Internet Access's official app (... but i'm switching to NordVPN in 2 months because in need of a dedicated IP-address)

The ultimate test would be doing it while having my VPN completely shutdown (killswitch off and everything)
The problem is that it's not always failing. The failing seems to be just random.

Anyway, which condition would better tell if a reliable datatransfer is possible?... "Host Reachable" or "Network Connected"?
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Network Connection

Post by Desmanto » 26 Jun 2018 15:51

Wow, high end router. If it is asus already, then the problem should be somewhere else.

Since the problem is intermittent, you have to log it when it happens. Use Host Reachable is better, since not only it ensure the network is connected, but it will check again if the host is really reachable. I assume your flow fail in some of the elements, stopped immediately by the error. Just attach debug dialog onto those elements and change the connection to exception. So you know when it happens. Or if you want to check the problem across a broader time span, you can save the error message to a glovar (or just use my variable logger script to log it).

If the problem also related to the network state, it might be a good idea to check the condition Active Network Type. Check all and use the true branch, so you get the network type and stated (including the extra info). You can analyze the logged glovar and see if you can spot a pattern fo the problem.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: Network Connection

Post by digitalstone » 26 Jun 2018 23:13

"Host Reachable" is better, yeah because of the actual feedback from the specific address of course.
Thanks

After a couple of tests it seems that indeed the VPN's process of handling things is a bit unpredictable.
There is a full stable connection with the VPN-server once established, that's for sure.

Problems are:
- Local network seems sometimes not to work at random times (they're working on the bug).
*and*
- As the network type switches from wifi to mobile (or coming from airplane mode), a new connection will be established with standard external IP from ISP.
Then this flow gets called of course to ping the correct IP to check my external IP at [http:///ipv4bot.whatismyipaddress.com], while in the meantime the VPN app on my phone is blocking all traffic except the VPN-server, which is the moment the ping sort of hangs because it's essentially waiting for connection establishing with the VPN-server, in order to retrieve the ping back from [www.google.com].

So... what i now need to figure out is:
How to specifically read when the VPN app on my phone has established secure VPN-connection with the VPN-server.
But the area of reading app internal info is something i really need a kickstart with
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Network Connection

Post by Desmanto » 27 Jun 2018 17:50

Never test it out, I only use VPN rarely.

Can you just ping the VPN server IP? Or maybe does it have some sort of DNS/gateway you can ping? Or maybe the VPN create a notification/service that you can check.

You can try to use raw ping command, and set the timeout to 1-5 seconds. So it will fail faster to let you know that the connection is not reachable.

Code: Select all

ping -c 1 www.google.com
Loop this with some sleep in the middle, example sleep 5 seconds.

Unless the app exposed something that we can check, I think the only way to check if it is connected, is to test the connection directly (kinda pointless :D). I should make some test later, but still busy to catch on the other forum. There will be a change of thread soon, so have to finish it first before moving to new thread.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: Network Connection

Post by digitalstone » 28 Jun 2018 09:51

Well pinging any server IP is possible whenever any connection is established i guess, VPN or not.
Since there is just a small time gap of normal ISP connection before the VPN app kicks in order to build a network configuration, pinging alone will be almost completely pointless because it will never be finished at this stage, and it would still not tell me what i am connected through myself (well duh, what was i thinking when building these flows? :( )

New Solution (i think):
Notification Extraction
The app itself exposes indeed some (very) realtime usable status-information in the form of a notification (thanks Desmanto, i didn't realized this earlier)
I'll just place action "sleep" 3 sec and then extract information from it while doing all that just locally on the phone itself.
This way it's unnecessary to send send signals all over the place while still through ISP, and letting the VPN app doing its part of the work for twice its worth.

Connection Usability
Pinging the correct IP (IP based on situation when {ping_ip} is null. this variable will optionally be send by the calling flow). Checkloop on this, followed with a ping_result=true/false on flow exit.

Double Check VPN-Connection
After that i'll let it perform a "double check" by requesting my IP through [http://ipv4bot.whatismyipaddress.com] within the IP-Request flow.
This way it will be possible to even crosslink both data from the native VPN app and the HTTP Request by retrieving the IP through [http://ipv4bot.whatismyipaddress.com]
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Network Connection

Post by Desmanto » 29 Jun 2018 18:02

I think you should have finish the flow already. But if not yet, you can log the notification from the VPN app during the connection. So you can know which one is the last notification before it changes the state to connected. Use that one as the final trigger to execute the ping and checking the IP address. It is much accurate than checking the first notification, as it might have problem in connecting and takes much longer time.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: Network Connection

Post by digitalstone » 29 Jun 2018 19:14

I actually didn't finish the flow yet. Yesterday i was a chaotic day. Today i worked like 10 hours and i just took a nap. Finally weekend where i can finish this flow.
Your method is how i was planned to do actually.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

Post Reply