import java.net.Socket; import java.net.UnknownHostException; import java.net.ConnectException; import java.io.*; public class Flash843 { public static void main(String[] args) { if(args == null || args.length == 0 || args[0] == null || args[0].length() == 0) { usage(); } else if("-h".equalsIgnoreCase(args[0]) || "/h".equalsIgnoreCase(args[0]) || "-?".equals(args[0]) || "/?".equals(args[0])) { usage(); } else { int port = 843; if(args.length > 1) { try { port = Integer.parseInt(args[1]); } catch(NumberFormatException nfe) { port = 843; } } Socket socket = null; PrintWriter dataOut = null; BufferedReader dataIn = null; try { socket = new Socket(args[0], port); dataOut = new PrintWriter(socket.getOutputStream(), true); dataIn = new BufferedReader(new InputStreamReader(socket.getInputStream())); dataOut.print("\0"); dataOut.flush(); String line = dataIn.readLine(); while(line != null) { System.out.println(line); line = dataIn.readLine(); } } catch(UnknownHostException uhe) { System.out.println("Error: The specified host is unknown."); } catch(ConnectException ce) { System.out.println("Error: No server to connect to on that port."); } catch(IOException ioe) { System.out.println("Error:"); ioe.printStackTrace(); } finally { if(dataOut != null) { dataOut.close(); } if(dataIn != null) { try { dataIn.close(); } catch (IOException e) { // do nothing } } if(socket != null) { try { socket.close(); } catch (IOException e) { // do nothing } } } } } private static void usage() { System.out.println(""); System.out.println("Usage:"); System.out.println(" java Flash843 (-h | /h | -? | /?) | (ipaddress [port])"); System.out.println(""); System.out.println("where"); System.out.println(" -h, /h, -?, /? - outputs this usage information"); System.out.println(" ipaddress - (required) the IP address to connect to"); System.out.println(" port - (optional) the port number to connect to (defaults to 843)"); System.out.println(""); System.out.println("For example: java Flash843 localhost 843"); System.out.println(""); } }