Can JavaScript Ping a Server, and How Reliable Is This Method?
Can Javascript Ping a Server?
In the endeavor to monitor server availability, a developer encountered a dilemma where page loading time soared to 60 seconds for just eight servers. Seeking a solution, they pondered the possibility of pinging servers from the client-side via JavaScript.
Fortunately, a resourceful individual shared a clever technique using the Image object. This function initiates a ping:
function Pinger_ping(ip, callback) { if(!this.inUse) { this.inUse = true; this.callback = callback this.ip = ip; var _that = this; this.img = new Image(); this.img.onload = function() {_that.good();}; this.img.onerror = function() {_that.good();}; this.start = new Date().getTime(); this.img.src = "http://" + ip; this.timer = setTimeout(function() { _that.bad();}, 1500); } }
This approach relies on the Image object to check server availability. The mechanism proved effective for various server types and ports. However, its reliability has reportedly diminished, and Chrome may no longer support it, resulting in an error.
The above is the detailed content of Can JavaScript Ping a Server, and How Reliable Is This Method?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Replace String Characters in JavaScript

HTTP Debugging with Node and http-console

Custom Google Search API Setup Tutorial
