简体   繁体   中英

How to detect nearest server to test latency/ping speed using Javascript?

I'm implementing a browser extension which should connect to the nearest server to test the ping speed.

To have more details, kindly have a look on SpeedTest , it first calculates the ping time.
And to calculate this ping time, it detects the nearest servers and then pings it.

For example, here's the nearest servers detected by SpeedTest . I marked them in red arrows

SpeedTest检测到最近的服务器


How does SpeedTest detect these servers ?

ie How can I detect the nearest servers and their locations in javascript as SpeedTest does ?

What speedtest is doing is not a real "ping" in the sense of having the client machine run a ping operation. I have no knowledge of their exact methods (and I believe they use flash rather than pure JS, or at least used to), but I would guess that they try to access a small resource (an empty text/image file?) on each of these machines, and then time the response back. That is certainly one way to implement this anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM