Two methods of checking the connectivity of java server code sharing

First, you should understand the content of Ping.

summary

Ping (packet Internet groper), an internet packet explorer, is a program used to test the amount of network connection. Ping sends an ICMP (Internet Control Messages Protocol), that is, the Internet message control protocol; the echo request message is sent to the destination and reports whether the desired icmpeecho is received (ICMP echo response). It is a command used to check whether the network is unobstructed or the network connection speed. As an administrator or hacker living on the network, the ping command is the first DOS command that must be mastered. Its principle is as follows: make use of the uniqueness of the machine IP address on the network, send a data packet to the target IP address, and then ask the other party to return it Return a packet of the same size to determine whether the two network machines are connected and what the delay is.

Ping refers to end-to-end connectivity, which is usually used as an availability check. However, some virus Trojans will force a large number of remote Ping commands to seize your network resources, resulting in slower system and slower network speed. Ping intrusion is strictly prohibited. As a basic function of most firewalls, it is provided to users for selection. Usually, if you don't use it as a server or network test, you can safely select it to protect your computer.

The ping command is usually used to check the connectivity of the server. The Java code is implemented as follows:

Method 1:

Ping in Java is implemented with a new function isreachable () after JDK 1.5, but the result usually returns false

Reason: this method is used to test whether the address can be reached. The implementation tries its best to reach the host, but the firewall and server configuration may block requests and make them unreachable When certain ports are accessible. If permission can be obtained, the typical implementation will use ICMP echo request; Otherwise, it will attempt to establish a TCP connection on port 7 (echo) of the target host.

Method 2 (recommended):

Use socket to do telnet operation on the port, and the result is more accurate

summary

The above is all about the code sharing of the two methods of checking the connectivity of the java server. I hope it will be helpful to you. Interested friends can continue to refer to this website:

Java programming using socket multithreading to access server file code example

Java multithreading programming socket communication example code

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>