@Override
    public void connect(final SocketAddress endpoint, final int timeout) throws IOException {
        final CountDownLatch signal = new CountDownLatch(1);
        final Thread t = threadFactory.newThread(new Runnable() {
            @Override
            public void run() {
                try {
                    connect(endpoint);
                }
                catch(IOException e) {
                    exception = e;
                }
                finally {
                    signal.countDown();
                }
            }
        });
        t.start();
        try {
            // Wait for #run to finish
            if(!signal.await(timeout, TimeUnit.MILLISECONDS)) {
                throw new SocketTimeoutException();
            }
        }
        catch(InterruptedException e) {
            final SocketTimeoutException s = new SocketTimeoutException(e.getMessage());
            s.initCause(e);
            throw s;
        }
        if(exception != null) {
            throw exception;
        }
    }
@Test(expected = SocketTimeoutException.class)
    public void testConnect() throws Exception {
        new UDTSocket().connect(new InetSocketAddress("localhost", 11111), 1000);
    }