Java Timing Detection Server port state method (i)

Source: Internet
Author: User


Recently in the operation and maintenance management platform to determine the timing of the cluster Server port open state to judge the process status of the scheduled task. By the way, the next Java how to detect the server one or more ports, and how to add to the scheduled task.

One, in Java with the Socket detection Server one port open state. (Not very familiar with the socket, only recently used to see the next simple)

    The English meaning of the  socket is "hole" or "socket". As a BSD Unix process communication mechanism, Take the latter one meaning. Often also referred to as "socket and Port, is a handle to a communication chain. Hosts on the internet

The socket and ServerSocket class libraries are located in the java.net package. ServerSocket is used for server-side, socket is used when establishing network connection. When the connection succeeds, a socket instance is generated at both ends of the application, manipulating the instance to complete the required session. For a network connection, sockets are equal, and there is no difference, not due to different levels on the server side or on the client. (Baidu Encyclopedia)


Personal implementation of the idea is: the passed in the IP first place in the list of the first position, in order to facilitate the return of the IP and port corresponding. You can also use set to pass the return value in a better way, and the IP is tagged in the object that calls the check method.

Subclasses of SocketAddress in java.net inetsocketaddress This class implements IP socket addresses (IP address + port number)

/**

*

* @param IP

* @param Port

* @return

*/

Public List Check (String ip,string port) {

List<string> results=new arraylist<string> ();

Results.add (0,IP);

try {

int Intport=integer.parseint (port);

Socket socket=new socket ();

socketaddress add = new inetsocketaddress (ip,intport);

Socket.connect (add,50);

Socket.close ();

Results.add (port);

return results;

} catch (Exception e) {

TODO auto-generated Catch block

return null;

}

}

Java Timing Detection Server port state method (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.