try { // process command-line arguments for (optind = 0; optind < argv.length; ++optind) { if (!argv[optind].substring(0,1).equals("-") || argv[optind].equals("--")) break; // end of options if (argv[optind].equals("-p")) { // -p port if (++optind >= argv.length) { System.err.println(usage); System.exit(1); } port = (new Integer(argv[optind])).intValue(); } else if (argv[optind].equals("-h")) { // -h host if (++optind >= argv.length) { System.err.println(usage); System.exit(1); } host = argv[optind]; } else { System.err.println(usage); System.exit(1); } } } catch (NumberFormatException e) { System.err.println("bad number format"); System.err.println(usage); System.exit(1); }