javascript - How to determine latency of a remote server through the browser -


I run some game tunnel servers and would like to keep a page where the client can ping on all servers and find out Who is most responsible for as far as I can see that there is no proper way to do this in javascript, but I was wondering, did anyone know how to do this in Flash or some other client browser technology?

Most applet technology, including javascript, implements a same-basic policy DOM elements dynamically It is possible to add, collect images of time using images, and onload event handlers.

psuedo-code

 for  (server in server) {var img = document.createElement ('IMG'); Server.startTime = getCurrentTimeInMS (); Img.onload = function () {server.endTime = getcurrentTimeInms (); } Img.src = server.imgUrl; }  

Then wait for a reasonable time and check the time for each server object. Repeat as needed and calculate the average if you want I'm not sure what type of accuracy you can expect.

Disadvantages:

  • You are probably using a wrong tool for a job. A browser is not equipped for this kind of application.
  • This is probably quite wrong.
  • If the resource you requested is cached, it will not give you the desired results, but you can change the URL to work at that time.
  • This is a bandwidth-intensive image compared to a normal ping, such as a spacer.gif file.
  • This time only depends on the latency of the remote server, but the bandwidth of that server may be more or less useful, but it is important to note that this is not just latency.
  • You should be able to fulfill HTTP requests from different servers and, importantly, the exact same resource (or a resource of equal length) on each server can affect the status response time on the server. , As if one server is compressing the data and the other is not.

Comments