Home Web Front-end JS Tutorial JavaScript simulated Ping effect code (Web Ping)_javascript skills

JavaScript simulated Ping effect code (Web Ping)_javascript skills

May 16, 2016 pm 06:09 PM
ping

Of course, the length of the HTTP header cannot be counted during the request, so when the request packet length is at the critical point of the maximum transmission unit, additional HTTP headers can cause IP packets, so there is a certain error. (2009/6/21)

Online demo: http://demo.jb51.net/js/2011/ping/

Core code:

Copy code The code is as follows:



<머리>

HTTP Ping
<스타일>
html
{
높이: 100%;
오버플로: 숨김;
}
본문
{
배경: #000;
색상: #C0C0C0;
글꼴 두께: 굵게;
글꼴 크기: 14px;
글꼴군: Lucida Console;
높이: 100%;
여백: 0 0 0 5px;
}
#divContent
{
높이: 90%;
오버플로: 자동;
}
#txtTimeout
{
너비: 40px;
}
버튼
{
여백-왼쪽: 10px;
}


<본문>

URL:

시간 초과:


<시간/>


<스크립트>
var intStartTime;
var objIMG = 새 이미지();
objIMG.onload =
objIMG.onerror =
function()
{
/*
* 有回应,取消超时计时
*/
clearTimeout(intTimerID );
if(!bolIsRunning || bolIsTimeout)
return;
var Delay = new Date() - intStartTime;
println(""
strURL
" 시간의 응답"
((delay<1)?("<1"):("="delay))
"ms" );
arrDelays.push(지연);
/*
* 每次请求间隔限system 1秒以上
*/
setTimeout(ping, Delay<1000?(1000-delay):1000);
}
function ping()
{
/*
* 发送请求
*/
intStartTime = new Date();
intSent ;
objIMG.src = strURL "/" intStartTime;
bolIsTimeout = false;
/*
* 超时计时
*/
intTimerID = setTimeout(timeout, intTimeout);
}
함수 timeout()
{
if(!bolIsRunning)
return;
bolIsTimeout = true;
objIMG.src = "X:\";
println("요청 시간이 초과되었습니다.");
핑();
}

<스크립트>
var $ = function(v){return document.getElementById(v)};
var arrDelays = [];
var intSent;
var bolIsRunning = false;
var bolIsTimeout;
var strURL;
var intTimeout;
var intTimerID;
var objBtn = $("btnSwitch");
var objContent = $("divContent");
var objTxtURL = $("txtURL");
objTxtURL.value = window.location.host;
function handlerBtnClick()
{
if(bolIsRunning)
{
/*
* 停止
*/
var intRecv = arrDelays.length;
var intLost = intSent-intRecv;
var sum = 0;
for(var i=0; isum = arrDelays[i];
objBtn.value = "시작";
bolIsRunning = false;
/*
* 统计结果
*/
println(" ");
println("" strURL "에 대한 핑 통계:");
println("  Packets: Sent = "
intSent
", Receivered = "
intRecv
", Lost = "
intLost
" ("
Math. Floor(intLost / intSent * 100)
"% 손실),");
if(intRecv == 0)
return;
println("밀리초 단위의 대략적인 왕복 시간:");
println("  Minimum = "
Math.min.apply(this, arrDelays)
"ms, Maximum = "
Math.max.apply(this, arrDelays)
"ms, 평균 = "
Math.floor(sum/intRecv)
"ms");
}
else
{
/*
* 开始
*/
strURL = objTxtURL.value;
if(strURL.length == 0)
return;
if(strURL.substring(0,7).toLowerCase() != "http://")
strURL = "http://" strURL;
intTimeout = parsInt($("txtTimeout").value, 10);
if(isNaN(intTimeout))
intTimeout = 2000;
if(intTimeout < 1000)
intTimeout = 1000;
objBtn.value = "중지";
bolIsRunning = true;
arrDelays = [];
intSent = 0;
cls();
println("핑 " strURL ":");
println(" ");
핑();
}
}
function println(str)
{
var objDIV = document.createElement("div");
if(objDIV.innerText != null)
objDIV.innerText = str;
그 외
objDIV.textContent = str;
objContent.appendChild(objDIV);
objContent.scrollTop = objContent.scrollHeight;
}
함수 cls()
{
objContent.innerHTML = "";
}



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to fix Xbox Series S/X download speeds, reduced ping and lag How to fix Xbox Series S/X download speeds, reduced ping and lag Apr 16, 2023 pm 04:49 PM

Xbox consoles have improved dramatically over the years. Over the years, games have evolved with life-like features that gamers can't seem to get enough of. Playing your favorite games on Xbox can be a completely engrossing experience. However, sometimes using these advanced features, we end up with lag or ping issues if the internet speed is not that good. Sometimes we want games to download faster. Today, games like Forza Horizon 5 and Mortal Kombat require over 100GB of RAM. Downloading such games can take a long time if we don't have the right internet settings to help us. Method 1: Pass

What is the reason for the ping request timeout? What is the reason for the ping request timeout? Aug 28, 2023 pm 04:17 PM

The reasons for the ping request timeout include unreachable target host, network congestion, firewall or security settings, and DNS resolution issues. Detailed introduction: 1. The target host is unreachable. The Ping request timeout may mean that the target host cannot be accessed through the network. This may be due to the target host closing the network connection, the network where the target host is located failing, the target host IP address being set incorrectly, etc. ; 2. Network congestion. Ping request timeout may also be caused by network congestion. Network congestion may be due to large amounts of data transmission, network equipment failures, etc.

Why can't I ping the gateway? Why can't ping? Why can't I ping the gateway? Why can't ping? Mar 13, 2024 pm 03:40 PM

The network cannot ping, what's going on? In fact, this is a very common problem. It is mainly divided into two situations: pinging fails on the same network segment and pinging fails on different network segments. Let’s take a look at the details below. There are usually two reasons why the ping command cannot connect to the same network segment: one is an IP address that cannot be pinged in the same network segment, and the other is an IP address that cannot be pinged in a different network segment. These two situations have different solutions. First, let’s discuss the situation where ping fails within the same network segment. 1. Ping fails on the same network segment, and the result is "Unable to access the target host." The destination IP and source IP are on the same network segment, and the ping result is &l

How to solve the error message 'ping is not recognized as an internal or external command or an operable program' How to solve the error message 'ping is not recognized as an internal or external command or an operable program' Feb 22, 2023 pm 04:28 PM

Solution: 1. Click the "Start" button, click "Control Panel" - "System" in the start menu; 2. In the settings interface, click "Advanced System Settings" - "Advanced" - "Environment Variables"; 3. . Check whether there is a Path variable in Administrator's user variables. If you do not see this variable, click "New" and add the variable Path and variable value.

What are the reasons why the IP address cannot be pinged? What are the reasons why the IP address cannot be pinged? Dec 15, 2020 pm 04:37 PM

The reasons why the IP address cannot be pinged are: 1. The other party is shut down or the IP address does not exist; 2. The network segment is different and cannot be found through routing; 3. The firewall filters the ICMP packets sent by ping; 4. The IP address is set incorrectly; 5. Network cable failure; 6. The gateway is not set.

The ttl value of ping briefly determines the operating system categories. The ttl value of ping briefly determines the operating system categories. May 22, 2023 am 09:04 AM

The type of some operating systems can often be roughly judged by the ttl value of ping. Here is a summary: The TTL field value of the ICMP echo response of UNIX and UNIX-like operating systems is 255. CompaqTru645.0 The TTL field value of the ICMP echo response is 64. The TTL field value of the ICMP echo response of the Microsoft Windows NT/2K operating system is 128. The TTL field value of the ICMP echo response of the Microsoft Windows 95 operating system is 32. Of course, these ttl values ​​can also be changed. Windows series systems can modify the following key values ​​in the registry. Implementation: [HKEY_LOCAL_MACHINE\system\Curren

Several simple examples of using the linux ping command Several simple examples of using the linux ping command Jan 09, 2024 am 08:26 AM

I found that there are quite a lot of ping commands under Linux. Here are a few examples: 1. pingwww.baidu.com, the roughest usage. At this time, the host will continue to send ICMPechorequest packets to the destination address until you press Ctrl +c2, ping-Ieth0www.baidu.com or ping-I192.168.8.151www.baidu.com, that is, the -I option can specify the network card that sends the ping packet. -I can be followed by the network card name or the IP address of the network card. 3. Ping-c3www.baidu.com, the -c option can specify how many ICMP packets to send, and you can see the host connection

what is ping what is ping Aug 04, 2023 pm 01:31 PM

Ping is a computer network tool used to test connectivity between hosts. By sending ICMP echo request messages to determine whether the target host is reachable, and measuring indicators such as round-trip delay time and packet loss rate, ping can help programmers diagnose network problems, optimize network performance, and ensure the stability of network connections.

See all articles