Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
How to Ping a Server using JavaScript?
A server ping can be defined as hitting a server and getting a response in return from that server. The idea is to send an echo message that will keep the health check and check whether the server is up and running or not. On sending a PING every server sends a PONG that shows that the server is active. Ping messages are sent by the ICMP (Internet Control Messaging Protocol). The lower the ping time the stronger the connection between the host and the server.
Approach
We can use a JavaScript function for sending the Ping messages to the server. In this tutorial, we will be sending the Pings by using the AJAX functionality and then displaying the response once the Pong is received. We will also examine the status code received to find whether the server is active or not. If any status other than 200 is received it means the server is not active or not working properly.
Example
In the below example, we have created a simple HTML page that will ping a specific path and return its response.
# index.html
Pinging the Server Welcome To Tutorials Point
Output



