@Override
	public void connect() throws IOException {
		if (regLevel != 0) // otherwise disconnected or connect
			throw new SocketException("Socket closed or already open ("+ regLevel +")");
		IOException exception = null;
		if (trustManagers.size() == 0)
			addTrustManager(new SSLDefaultTrustManager());
		SSLSocketFactory sf = null;
		SSLSocket s = null;
		try {
			if (sf == null)
				sf = SSLSocketFactoryFactory.createSSLSocketFactory(getTrustManagers());
			s = (SSLSocket)sf.createSocket(host, port);
			s.startHandshake();
			exception = null;
		} catch (SSLNotSupportedException exc) {
			if (s != null)
				s.close();
			s = null;
			throw exc;
		} catch (IOException exc) {
			if (s != null)
				s.close();
			s = null;
			exception = exc; 
		}

		if (exception != null)
			throw exception; // connection wasn't successful at any port

		prepare(s);
	}