(What does this program actually do)
import java.io.*;
import java.net.*;
public class prog4 {
public final static int ECHO_PORT = 7;
public static void main(String argv[]) {
if (argv.length != 1) {
System.out.println("Usage: java prog4 hostname"
System.exit(0);
}
if (alive(argv[0])) {
System.out.println(argv[0] + " is alive"
} else {
System.out.println("No response from " + argv[0] +". Host is down or does not exist"
}
}
public static boolean alive(String host) {
Socket prog4Socket = null;
try {
prog4Socket = new Socket(host, ECHO_PORT);
} catch (UnknownHostException e) {
System.err.println("UnknownHostException: " +e);
} catch (IOException io) {
System.out.println("IOException: " + io);
}
if (prog4Socket != null) {
try {
prog4Socket.close();
} catch (IOException e) {
System.err.println("IOException: " + e);
}
return true;
} else {
return false;
}
}
}
import java.io.*;
import java.net.*;
public class prog4 {
public final static int ECHO_PORT = 7;
public static void main(String argv[]) {
if (argv.length != 1) {
System.out.println("Usage: java prog4 hostname"
System.exit(0);
}
if (alive(argv[0])) {
System.out.println(argv[0] + " is alive"
} else {
System.out.println("No response from " + argv[0] +". Host is down or does not exist"
}
}
public static boolean alive(String host) {
Socket prog4Socket = null;
try {
prog4Socket = new Socket(host, ECHO_PORT);
} catch (UnknownHostException e) {
System.err.println("UnknownHostException: " +e);
} catch (IOException io) {
System.out.println("IOException: " + io);
}
if (prog4Socket != null) {
try {
prog4Socket.close();
} catch (IOException e) {
System.err.println("IOException: " + e);
}
return true;
} else {
return false;
}
}
}