int CTCPClient::ConnectServer(CHost &server, int port) { if (server.naddr() < 1) return -1; for (unsigned i=0; i<server.naddr(); i++) { #ifdef _DEBUG cerr<<"connect try: "<<i<<endl; #endif //_DEBUG string addr = server.address(); if (addr.empty()) throw runtime_error("Empty net_addr string from DNS."); #ifdef _DEBUG time_t start = time(0); #endif //_DEBUG if (ConnectServer(addr.c_str(), addr.size(), port)==0) { #ifdef _DEBUG cerr<<"Use "<<time(0)-start<<" seconds, Success!"<<endl; #endif //_DEBUG return 0; } server.next(); #ifdef _DEBUG cerr<<"Use "<<time(0)-start<<" seconds, Failed!"<<endl; #endif //_DEBUG } return -2; }