Código Proxy
import java.io.*;  import java.net.*;



interface SocketInterface {
  String readLine();
  void  writeLine( String str );
  void  dispose();
}

public class ProxyDemo {
  public static void main( String[] args ) {

    
    SocketInterface socket = new SocketProxy( "127.0.0.1", 8189,
      args[0].equals("first") ? true : false );

    String  str = null;
    boolean skip = true;
    while (true) {
      if (args[0].equals("second")  &&  skip) {
        skip = ! skip;
      }
      else {
        str = socket.readLine();
        System.out.println( "Receive - " + str );  
        if (str.equals("quit")) break;                   }                                                  System.out.print( "Send ---- " );            
      str = Read.aString();                        
      socket.writeLine( str );                     
      if (str.equals("quit")) break;                   }                                                 socket.dispose();                               }
}

class SocketProxy implements SocketInterface {
  private Socket      socket;
  private BufferedReader in;
  private PrintWriter   out;

  public SocketProxy( String host, int port, boolean wait ) {
    try {
      if (wait) {
        in the wrapper
        ServerSocket server = new ServerSocket( port );
        socket = server.accept();
      } else
        socket = new Socket( host, port );
        in  = new BufferedReader( new InputStreamReader(
                                        socket.getInputStream()));
        out = new PrintWriter( socket.getOutputStream(), true );
      } catch( IOException e ) {
        e.printStackTrace();
      }
  }
  public String readLine() {
    String str = null;
    try {
      str = in.readLine();
    } catch( IOException e ) {
      e.printStackTrace();
    }
    return str;
  }
  public void writeLine( String str ) {
    
    out.println( str );
  }
  public void dispose() {
    try {
      socket.close();
    } catch( IOException e ) {
      e.printStackTrace();
    }
  }
}