Android - How to measure bandwidth quality within local network with just one phone
Asked Answered
C

2

10

Our app serves as a controller for our Wi-Fi enabled devices. Sometimes, when the local network traffic is terrible, it is hard for the devices to receive the command that the controller app sends. If this happens, we need to notify the user that the network traffic is terrible and tell the user to switch to another router.

We do have a heartbeat with the devices that we are going to control. However, the problem might occur without even reaching that stage. I mean that, first of all our app needs to search for the devices by sending UDP packets to a multicast address. Then after we receive the response from those devices, we then create a connection between them. That is the time we can get the heartbeat. The problem I am talking about is even at the stage of just searching for the devices, if the network traffic is terrible, our device will not be able to receive the UDP packets that we sent.

So far, these were our attempts:

  1. Starting an http server and a client

We started a lightweight http server, placed a file there. Then we create a client and download that file, and monitor the speed. But this seems to be not working because there is a loopback. The device sees that the two sides(http client and server) are of the same zone(maybe the term is wrong) so maybe the download didn't even pass the router.

  1. Integrate iPerf into our app:

The downside of this solution is that the device needs to be rooted. But still we tried iPerf's solution. We tested it with both client and server in the same device. But still the speed is not changing. If we test in two devices, one as server, another as client, then we get a good speed test. However, we cannot as our client to use two phones for our product, and we cannot ask them to root their phone either.

  1. Using the open source lib for connection speed checking provided by Facebook.

We found an open source lib in github that checks for the connection speed quality. However, this requires internet connection in order to check the speed. But our product doesn't require user to have internet connection. The user just needs a router and an app. So, unfortunately, we cannot use this solution.

  1. Tried searching for how to disable the loopback when downloading a file from same device.

Based on our first attempt, which is the only solution that we built by our selves. we tried to check in the documentation if there is anyway to disable loopback when downloading a file from same device. Unfortunately, we did not get any good result.

So, our question is:

  1. If our first attempt is close, then how can we disable this loopback thing so that we can properly monitor the download speed?

  2. If our first attempt is not good enough, then is there any other way that we can do to test the bandwidth locally?

Note: There shouldn't be any internet connection and not more than one phone should be used.

Thanks in advance!

Corinecorinna answered 17/12, 2016 at 4:24 Comment(9)
If you have wifi devices communicating with your app - can't they have a 'heartbeat' where if you lose connectivity - you prompt the user. With idea (1) are the http server and client on the same machine? If not - you can use a proxy like wireshark to check if any communications traffic occurs.Calie
@MorrisonChang Yes, our devices do have a heartbeat. But that only happens when the app already found the devices and then connected to them through socket connection. I will update my question. Thanks!Corinecorinna
@MorrisonChang yes, both server and client are on the same machinesCorinecorinna
Is there a problem with watching the initial startup and prompting the user with an information if no devices were found after scanning?Bignonia
@Bignonia prompting the user that no devices were found after scanning is common. But, we need to tell the user WHY there are no devices found when the devices are just there by their side. We have to give acceptable reasons. Or else the user will think that our device is problematic, which is most of the time not the case.Corinecorinna
sure but there are not many reasons that no device is found. I can first guess that the server is not reachable, that really no devices are there, that the traffic is too bad and that there is a problem with the device. So you start the app, test the availability of the server, after that is verified you try to search for devices. If no devices are found it could have two reasons so you might need a validated resource to get an information if it should find devices. I guess you already tried it but what about developer.android.com/reference/android/net/…Bignonia
@Bignonia Hi, thanks but there seems to be no method under that class for us to check the quality of bandwidth.Corinecorinna
Not directly but if you look at developer.android.com/reference/android/net/… you can see it goes kinda in the right direction. Also this developer.android.com/reference/android/net/TrafficStats.html looks kinda interesting for your needs. I agree that a sdk would be way more convenient but maybe you have to do it yourself with the network classes.Bignonia
@Bignonia alright, thanks. Will have a look then.Corinecorinna
R
1

This also is a good resource for detecting bandwidth on one phone

https://github.com/facebook/network-connection-class

Ronald answered 3/10, 2019 at 19:21 Comment(0)
M
0

Although this is a partial solution, it might help to check:

InetAddress.getByName(router).isReachable(timeOut)

As it is explained here , it will not always work, but if it does proofs that it is not a network problem.

It is also worth the effort to make an http and https request to the router IP address, since most commercial routers do provide a web interface.

Comparing subsequent response times could help you to asses the network state.

Malposition answered 19/12, 2016 at 14:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.