/** Main client entry point for stand-alone operation. */ public static void main(String[] args) { BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%d [%-25t] %-5p: %m%n"))); CmdLineParser parser = new CmdLineParser(); CmdLineParser.Option help = parser.addBooleanOption('h', "help"); CmdLineParser.Option output = parser.addStringOption('o', "output"); CmdLineParser.Option iface = parser.addStringOption('i', "iface"); try { parser.parse(args); } catch (CmdLineParser.OptionException oe) { System.err.println(oe.getMessage()); usage(System.err); System.exit(1); } // Display help and exit if requested if (Boolean.TRUE.equals(parser.getOptionValue(help))) { usage(System.out); System.exit(0); } String outputValue = (String) parser.getOptionValue(output, DEFAULT_OUTPUT_DIRECTORY); String ifaceValue = (String) parser.getOptionValue(iface); String[] otherArgs = parser.getRemainingArgs(); if (otherArgs.length != 1) { usage(System.err); System.exit(1); } try { Client c = new Client(getIPv4Address(ifaceValue)); SharedTorrent torrent = SharedTorrent.fromFile(new File(otherArgs[0]), new File(outputValue), false); c.addTorrent(torrent); // Set a shutdown hook that will stop the sharing/seeding and send // a STOPPED announce request. Runtime.getRuntime().addShutdownHook(new Thread(new ClientShutdown(c, null))); c.share(); if (ClientState.ERROR.equals(torrent.getClientState())) { System.exit(1); } } catch (Exception e) { logger.error("Fatal error: {}", e.getMessage(), e); System.exit(2); } }