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)