public static Socket doInteraction(final HttpsURLConnection clientConnection,final ServerSocket serverSocket,final int responseCode,final boolean doAuthentication) throws Throwable {
  clientConnection.setDoInput(true);
  clientConnection.setConnectTimeout(TIMEOUT);
  clientConnection.setReadTimeout(TIMEOUT);
  ServerWork server=new ServerWork(serverSocket,responseCode,doAuthentication);
  ClientConnectionWork client=new ClientConnectionWork(clientConnection);
  ExecutorService executorService=Executors.newFixedThreadPool(2);
  try {
    Future<Void> serverFuture=executorService.submit(server);
    Future<Void> clientFuture=executorService.submit(client);
    Throwable t=null;
    try {
      serverFuture.get(30,TimeUnit.SECONDS);
    }
 catch (    ExecutionException e) {
      t=e.getCause();
    }
    try {
      clientFuture.get(30,TimeUnit.SECONDS);
    }
 catch (    ExecutionException e) {
      if (t != null) {
        t.printStackTrace();
      }
      t=e.getCause();
    }
    if (t != null) {
      throw t;
    }
  }
 catch (  ExecutionException e) {
    throw e.getCause();
  }
 finally {
    executorService.shutdown();
  }
  return server.peerSocket;
}

public static Socket doInteraction ( final HttpsURLConnection clientConnection , final ServerSocket serverSocket , final int responseCode , final boolean doAuthentication ) throws Throwable { clientConnection . setDoInput ( true ) ; clientConnection . setConnectTimeout ( TIMEOUT ) ; clientConnection . setReadTimeout ( TIMEOUT ) ; ServerWork server = new ServerWork ( serverSocket , responseCode , doAuthentication ) ; ClientConnectionWork client = new ClientConnectionWork ( clientConnection ) ; ExecutorService executorService = Executors . newFixedThreadPool ( 2 ) ; try { Future < Void > serverFuture = executorService . submit ( server ) ; Future < Void > clientFuture = executorService . submit ( client ) ; Throwable t = null ; try { serverFuture . get ( 30 , TimeUnit . SECONDS ) ; } catch ( ExecutionException e ) { t = e . getCause ( ) ; } try { clientFuture . get ( 30 , TimeUnit . SECONDS ) ; } catch ( ExecutionException e ) { if ( t != null ) { t . printStackTrace ( ) ; } t = e . getCause ( ) ; } if ( t != null ) { throw t ; } } catch ( ExecutionException e ) { throw e . getCause ( ) ; } finally { executorService . shutdown ( ) ; } return server . peerSocket ; }
performs interaction between client ' s httpsurlconnection and servers side ( serversocket ) . server will response with specified response code .
