Пример #1
0
bool
IPAddress::operator==(const char *pcNewHostName) const
{
    IPAddress   cCheckAddr;

    cCheckAddr.SetHostName(pcNewHostName, (iAddressType == AF_INET6));
    return ((*this) == cCheckAddr);
}
Пример #2
0
void* MySocketThread::start_thread(void *arg)   {
    
    MySocketThread* thred=(MySocketThread*)arg;
    const char* serverIp=SERVER_IP;
    
    //定义客户端的ip,写客户端的ip
    
    int serverPort=SERVER_PORT;
    
    //定义客户端的端口
    
    //处理异常
    IPAddress address;
    try {
        
        address.SetHostName(serverIp, false);
        
        //false的意思是是否用这个ip与网络连接
        
       TCPClientSocket *socket=new TCPClientSocket(address,serverPort);
        
        // 设置超时
        
        struct timeval timeout;
        
        socklen_t len = sizeof(timeout);
        
        timeout.tv_sec = SOKETTIMEOUT;
        
        socket->SetSockOpt(SOL_SOCKET, SO_RCVTIMEO, &timeout, len);
        thred->csocket = socket;
//        thred->csocket->SetSockOpt(SOL_SOCKET, SO_RCVTIMEO, &timeout, len);
        
		 thred->state=0;
//		 ResPonseThread::GetInstance()->start();//// 启动响应参数
        
    } catch (SocketException &excep) {
        
        cout<<"Socket Exception:"<<(const  char *)excep<<endl;
        thred->state=1;
    }
    
    catch(...){
        thred->state=1;
        //这是c++里面的例外处理,catch(...)的意思是其他例外的出现
        
        cout<<"other error"<<endl;
        
    }
    
    
    

//	ODSocket cdSocket;
//	cdSocket.Init();
//	bool isok=cdSocket.Create(AF_INET,SOCK_STREAM,0);
//	bool iscon=cdSocket.Connect("127.0.0.1",8000);
//	if(iscon){
//		thred->state=0;
//		ResPonseThread::GetInstance()->start();//// 启动响应参数
//		CCLOG("conection");
//	}else{
//		thred->state=1;
//	}
//	thred->csocket=cdSocket;
	return NULL;
}