iOS Detecting connection speed or type [duplicate]
Asked Answered
F

1

9

Possible Duplicate:
Iphone detect 3g or wifi

is there a way to get the current network speed or if the device is on EDGE/3G/GPRS? I can use Reachability to distinguish WiFI from WMAN but that's not enough for my application.

Fotina answered 23/5, 2012 at 11:32 Comment(1)
@gunjotsingh the answer for initial question actually is here: https://mcmap.net/q/194806/-ios-detect-3g-or-wifi Although the question about connection speed was marked as duplicate for this...Outsoar
C
11

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

Setup a connection to a known server that has low latency. In a separate thread, mark the time (Time A) and send a packet (make sure it's one packet). Wait on that thread. Mark the time of the first packet (Time B). Read the data until finished. Mark the time of the last packet (Time C). Make sure the server response spans at least three packets.

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

Because you want to be accurate as possible, use the lowest level of network access you have available (I believe on the iPhone this is sockets). Use random data blocks of fixed lengths as both your request and response. A few bytes for the request should suffice, but the response needs to be well constructed. Make sure the server sends a small first packet, then a sequence of packets that is large enough to fill three or more.

At that point you will need to test. Test, test, test, and test. Test on the different network types, test with different amounts of network traffic, test with switching networks, and test anything else you can think of.

Counterblow answered 23/5, 2012 at 11:56 Comment(1)
interesting technical approach to this. So regardless of WIFI or 3G etc... This should give some ballpark estimate of available bandwidth. I was looking for a solution like this so I can logically decide to pull either large or smaller images across the network. The smaller ones preferred for lower bandwidth scenarioPhilippeville

© 2022 - 2024 — McMap. All rights reserved.