private String ask(String cmd) { BufferedWriter out = null; BufferedReader in = null; Socket sock = null; String ret = ""; try { System.out.println(server); sock = new Socket(server, ServerListener.PORT); out = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream())); out.write(cmd, 0, cmd.length()); out.flush(); in = new BufferedReader(new InputStreamReader(sock.getInputStream())); int inr = in.read(); while (inr != ';') { ret += Character.toString((char) inr); inr = in.read(); } } catch (IOException io) { io.printStackTrace(); } finally { try { out.close(); in.close(); sock.close(); } catch (IOException io) { io.printStackTrace(); } } return ret; }
// network-y stuff private void command(String cmd) { BufferedWriter out = null; try { Socket sock = new Socket(server, ServerListener.PORT); out = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream())); char[] oar = cmd.toCharArray(); for (char c : oar) { out.write(c); } out.flush(); } catch (IOException io) { io.printStackTrace(); } finally { try { out.close(); } catch (IOException io) { io.printStackTrace(); } } }