import java.io.*; import java.net.*; class ClientExample { public static final int PORT = 1234; public static void main(String argv[]) { try { Socket s = new Socket("localhost", PORT); BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream())); PrintWriter pr = new PrintWriter(new OutputStreamWriter(s.getOutputStream())); System.out.println(s.getLocalAddress().toString()); System.out.println(s.getLocalSocketAddress().toString()); pr.println("Hello, world!"); pr.flush(); System.out.println(br.readLine()); } catch (IOException e) { System.out.println("IO Exception: " + e.getMessage()); } } }