How to determine latency of a remote server through the browser

后端 未结 9 782
暖寄归人
暖寄归人 2020-12-17 15:41

I run a couple of game tunnelling servers and would like to have a page where the client can run a ping on all the servers and find out which is the most responsive. As far

9条回答
  •  盖世英雄少女心
    2020-12-17 16:14

    Based on the responses of @Mr. Shiny and @Georg Schölly , a complete and commented example.

    In order to test, just copy and paste the codes below in the same order, in a empty .html, .php or other compatible file.

    Before start the get, record the current Javascript time. Using new Date(), we create a new date object with the current date and time.

    
    

    Inside the function we have the variable endTime that receives a date time after the source image was loaded.

    Lastly, the ping variable receives the initial time minus the final time. The alert popup shows the result.

提交回复
热议问题