FileDocCategorySizeDatePackage
ConnectFriendly.javaAPI DocExample851Tue Mar 13 15:32:38 GMT 2001None

ConnectFriendly

public class ConnectFriendly extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] argv)

		String server_name = argv.length == 1 ? argv[0] : "localhost";
		int tcp_port = 80;
		try {
			Socket sock = new Socket(server_name, tcp_port);

			/* Finally, we can read and write on the socket. */
			System.out.println(" *** Connected to " + server_name  + " ***");
			/* ... */

			sock.close();

		} catch (UnknownHostException e) {
			System.err.println(server_name + " Unknown host");
			return;
		} catch (NoRouteToHostException e) {
			System.err.println(server_name + " Unreachable" );
			return;
		} catch (ConnectException e) {
			System.err.println(server_name + " connect refused");
			return;
		} catch (java.io.IOException e) {
			System.err.println(server_name + ' " + e.getMessage());
			return;
		}