public static Socket createSocket(String server,int port,long timeout) throws IOException {
  SocketWrapper socketWrapper=new SocketWrapper();
  socketWrapper.server=server;
  socketWrapper.port=port;
  Object sync=new Object();
  Thread socketThread=new Thread(new SocketRunnable(socketWrapper,sync));
  socketThread.setDaemon(true);
  Thread timeoutThread=new Thread(new TimeoutRunnable(sync,timeout * 1000));
  timeoutThread.setDaemon(true);
  timeoutThread.start();
  socketThread.start();
synchronized (sync) {
    if (socketWrapper.socket == null) {
      try {
        sync.wait(timeout * 1000);
      }
 catch (      InterruptedException e) {
        logger.trace("",e);
      }
    }
  }
  timeoutThread.interrupt();
  socketThread.interrupt();
  socketWrapper.valid=false;
  if (socketWrapper.getSocket() == null && socketWrapper.exception != null) {
    throw socketWrapper.exception;
  }
 else   if (socketWrapper.getSocket() == null) {
    throw new TimeoutException();
  }
  return socketWrapper.getSocket();
}

public static Socket createSocket ( String server , int port , long timeout ) throws IOException { SocketWrapper socketWrapper = new SocketWrapper ( ) ; socketWrapper . server = server ; socketWrapper . port = port ; Object sync = new Object ( ) ; Thread socketThread = new Thread ( new SocketRunnable ( socketWrapper , sync ) ) ; socketThread . setDaemon ( true ) ; Thread timeoutThread = new Thread ( new TimeoutRunnable ( sync , timeout * 1000 ) ) ; timeoutThread . setDaemon ( true ) ; timeoutThread . start ( ) ; socketThread . start ( ) ; synchronized ( sync ) { if ( socketWrapper . socket == null ) { try { sync . wait ( timeout * 1000 ) ; } catch ( InterruptedException e ) { logger . trace ( "" , e ) ; } } } timeoutThread . interrupt ( ) ; socketThread . interrupt ( ) ; socketWrapper . valid = false ; if ( socketWrapper . getSocket ( ) == null && socketWrapper . exception != null ) { throw socketWrapper . exception ; } else if ( socketWrapper . getSocket ( ) == null ) { throw new TimeoutException ( ) ; } return socketWrapper . getSocket ( ) ; }
creates a new asyncsocket object .
