import java.net.*; import java.io.*; public class hpMessage { public hpMessage() { } public static void main(String[] args) { if ( args.length < 2 ) { System.out.println("Usage: java hpMessage [host] [message]"); } else if ( sendMsg(args[0], args[1]) == false ) { System.out.println("Error: " + getError()); } } private static void setError(String msg) { ErrorMsg = msg; } public static String getError() { return ErrorMsg; } public static boolean sendMsg(String addr, String msg) { Socket hpSocket = null; PrintWriter out = null; // BufferedReader in = null; try { hpSocket = new Socket(addr,9100); out = new PrintWriter(hpSocket.getOutputStream(),true); // in = new BufferedReader(new InputStreamReader(hpSocket.getInputStream())); } catch (UnknownHostException e) { // Unknown host setError("Unknown host"); return false; } catch (ConnectException e) { // connection refused setError("Connection refused"); return false; } catch (NoRouteToHostException e) { // couldn't connect setError("Couldn't connect to host"); return false; } catch (IOException e) { // couldn't get I/O for connection setError("Unable to open I/O for connection"); return false; } // BufferedReader stdln = new BufferedReader(new InputStreamReader(System.in)); out.println( "\033%-12345X@PJL RDYMSG DISPLAY = \"" + msg + "\"\r\n\033%-12345X\r\n" ); // write to socket // in.readLine(); // read from socket try { out.close(); // in.close(); // stdln.close(); hpSocket.close(); } catch (IOException e) { } return true; } static String ErrorMsg; }