X-Git-Url: https://git.piment-noir.org/?p=TD_SR.git;a=blobdiff_plain;f=TD2%2FClientSimplifie.java;h=d247a9383cc852cc6094e63953740b1b9ec09ddf;hp=35f389dccfa6399625c942171a7b306ecd951835;hb=ce28a0211974450cf5df46e2065fb39350e029ec;hpb=f734b9878de62b987da4922fa796a691d16680ce diff --git a/TD2/ClientSimplifie.java b/TD2/ClientSimplifie.java index 35f389d..d247a93 100644 --- a/TD2/ClientSimplifie.java +++ b/TD2/ClientSimplifie.java @@ -26,11 +26,16 @@ public class ClientSimplifie { try { sock = new Socket(adresseIPServeur, portServeur); } - catch (IOException e) {} + catch (IOException e) { + System.err.println("IOException: " + e); + } InputStream IStream = null; try { IStream = sock.getInputStream(); - } catch (IOException e) {} + } + catch (IOException e) { + System.err.println("IOException: " + e); + } InputStreamReader IMesg = new InputStreamReader(IStream); lecture = new BufferedReader(IMesg); @@ -38,31 +43,48 @@ public class ClientSimplifie { try { OStream = sock.getOutputStream(); } - catch (IOException e) {} + catch (IOException e) { + System.err.println("IOException: " + e); + } ecriture = new PrintWriter(OStream); } + /** + * Send a message on the opened client socket + * @param msg a string containing the message to send + */ public void sendMsg(String msg) { - ecriture.println(msg + "\n"); + ecriture.println(msg); ecriture.flush(); } + /** + * Receive a message sent on the opened client socket + * @return a string containing the received message + */ public String receiveMsg() { String line = new String(); try { //FIXME: read only the line before the ending newline line = lecture.readLine(); } - catch (IOException e) {} + catch (IOException e) { + System.err.println("IOException: " + e); + } return line; } + /** + * Close all opened I/O streams attached to this object instance + */ public void closeRWIO() { ecriture.close(); - try { - lecture.close(); - } - catch (IOException e) {} + try { + lecture.close(); + } + catch (IOException e) { + System.err.println("IOException: " + e); + } } } // fin classe ClientSimplifie