Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can anyone tell me what other functionality i can add to this program?

Status
Not open for further replies.

clickshah

Programmer
Dec 12, 2001
3
GB
(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;
}
}
}
 
Your application looks like it tests for servers that listen on port 7, judging by the code, if the server will connect on port 7, then it reports the server is alive, if not, then it sends a Unknown Host Exception. I don't know TCP\IP standards for ports, but guessing by the ECHO_PORT, servers that listen on port 7 usually just echo whatever you type. Extra functionally to this program would be adding Input Readers and Output Writers so that you may actually use the echo servers? Just a suggestion on how it could be expanded some.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top