Check connection speed (bandwidth) in Xcode

Is there any way to check the Internet connection speed or bandwidth programmatically in Xcode. I try to do this because a slow connection creates problems for a specific image download.

+6
source share
1 answer

If you really need to know, you will have to test it.

Establish a connection to a known server with a low latency. In a separate thread, note the time (time A) and send the packet (make sure it is one packet). Wait on this topic. Note the time of the first packet (time B). Read the data to completion. Note the time of the last packet (time C). Verify that the server response takes at least three packets.

Time B - Time A is a very rough estimate of the delay. Time C - Time B - A very rough estimate of the bandwidth.

Since you want to be as accurate as possible, use the lowest network access available to you (I believe that these are sockets on the iPhone). Use random fixed-length data blocks for both your request and response. A few bytes for the request should be sufficient, but the answer should be well built. Make sure the server sends a small first packet, and then a sequence of packets that is large enough to fill three or more.

At this point you will need to test. Testing, testing, testing and testing. Test different types of networks, check the different volumes of network traffic, check the switching networks and check everything else that you might think about.

0
source

Source: https://habr.com/ru/post/920654/


All Articles