import java.net.*; import java.io.*; public class LedsClient { public static void main(String[] args) { String hostname = ""; if (args.length == 1) { hostname = args[0]; } else { System.err.println("Usage: LedsClient "); System.exit(0); } System.out.println("Type 0 to 7 to turn on/off LEDs."); System.out.println("Type '.' to end."); PrintWriter out = null; //BufferedReader networkIn = null; try { Socket theSocket = new Socket(hostname, 10); //networkIn = new BufferedReader( // new InputStreamReader(theSocket.getInputStream())); BufferedReader userIn = new BufferedReader( new InputStreamReader(System.in)); out = new PrintWriter(theSocket.getOutputStream()); System.out.println("Connected to LEDs server"); while (true) { String theLine = userIn.readLine(); if (theLine.equals(".")) break; char typedChar[] = new char[1]; char convertedChar[] = new char[1]; typedChar[0] = theLine.charAt(0); //convertedChar[0] = typedChar[0]; convertedChar[0] = (char) (typedChar[0] - '0'); String convertedLine = new String(convertedChar, 0, 1); out.println(convertedLine); //out.println(theLine); out.flush(); //System.out.println(networkIn.readLine()); } } // end try catch (IOException e) { System.err.println(e); } finally { //try { //if (networkIn != null) networkIn.close(); if (out != null) out.close(); //} //catch (IOException e) {} } } // end main } // end LedsClient