Hold one conversation across the net
try {
Socket sock = new Socket(hostName, 7); // echo server.
BufferedReader is = new BufferedReader(new
InputStreamReader(sock.getInputStream()));
PrintWriter os = new PrintWriter(sock.getOutputStream(), true);
// Do the CRLF ourself since println appends only a \r on
// platforms where that is the native line ending.
os.print(mesg + "\r\n"); os.flush();
String reply = is.readLine();
System.out.println("Sent \"" + mesg + "\"");
System.out.println("Got \"" + reply + "\"");
} catch (IOException e) {
System.err.println(e);
}