07.01.2013 Views

David Defour - Université de Perpignan

David Defour - Université de Perpignan

David Defour - Université de Perpignan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Helper Class: SocketUtils<br />

• I<strong>de</strong>a<br />

–It is common to make BufferedRea<strong>de</strong>r and PrintWriter from a<br />

Socket, so simplify the syntax slightly<br />

• Co<strong>de</strong><br />

public class SocketUtils {<br />

}<br />

548<br />

jeudi 26 janvier 12<br />

public static BufferedRea<strong>de</strong>r getRea<strong>de</strong>r(Socket s) throws IOException {<br />

return(new BufferedRea<strong>de</strong>r<br />

(new InputStreamRea<strong>de</strong>r(s.getInputStream())));<br />

}<br />

public static PrintWriter getWriter(Socket s) throws IOException {<br />

// Second argument of true means autoflush.<br />

return (new PrintWriter(s.getOutputStream(), true));<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!