1	// Simple client - sends lines to the server
    2	// and reads lines that the server sends.

    4	import java.net.*;
    5	import java.io.*;

    7	public class SimpleClient {

    9	    public static void main(String[ ] args) throws IOException {

   11	        System.out.println("CLIENT");
   12	        System.out.println();
   13	        // Passing null to getByName() produces the
   14	        // special "Local Loopback" IP address, for
   15	        // testing on one machine w/o a network:
   16	        InetAddress addr = InetAddress.getByName(null);
   17	        // Alternatively, you can use the address or name:
   18	        // InetAddress addr =
   19	        //        InetAddress.getByName("127.0.0.1");
   20	        // InetAddress addr =
   21	        //        InetAddress.getByName("localhost");
   22	        System.out.println("addr = " + addr);
   23	        Socket socket = new Socket(addr, SimpleServer.PORT);
   24	        // Guard everything in a try-finally to make
   25	        // sure that the socket is closed:
   26	        try {
   27	            System.out.println("socket = " + socket);
   28	            BufferedReader in =
   29	                new BufferedReader(
   30	                    new InputStreamReader(
   31	                        socket.getInputStream()));
   32	            // Output is flushed by PrintWriter:
   33	            PrintWriter out =
   34	                new PrintWriter(
   35	                    new BufferedWriter(
   36	                        new OutputStreamWriter(
   37	                            socket.getOutputStream())), true);
   38	            for(int i = 0; i < 10; i ++) {
   39	                out.println("Howdy " + i);
   40	                String str = in.readLine();
   41	                System.out.println(str);
   42	            }
   43	            System.out.println("END");
   44	            out.println("END");
   45	        } finally {
   46	            System.out.println("Closing...");
   47	            socket.close();
   48	        }
   49	        System.out.println();
   50	        System.out.println("* END CLIENT *");
   51	    }
   52	}

CLIENT

addr = localhost/127.0.0.1
socket = Socket[addr=localhost/127.0.0.1,port=8080,localport=1235]
Howdy 0
Howdy 1
Howdy 2
Howdy 3
Howdy 4
Howdy 5
Howdy 6
Howdy 7
Howdy 8
Howdy 9
END
Closing...

* END CLIENT *