Monkey original, reprinted. Reprinted Please note: Reprinted from cocos2d Development Network --cocos2dev.com, thank you!
Original address: http://www.cocos2dev.com /? P = 289
The socket connection is used in the project. Because of the boost I use, the boost connection can only be used to transmit IP addresses, while the server address is a domain name, so the domain name must be transferred to the IP address.
After reading the code, it is actually quite simple.
//SERVER_ADDRESS Server Domainhostent* host_entry = gethostbyname(SERVER_ADDRESS);char IPStr[64] = {0};if(host_entry !=0){sprintf(IPStr, "%d.%d.%d.%d",(host_entry->h_addr_list[0][0]&0x00ff),(host_entry->h_addr_list[0][1]&0x00ff),(host_entry->h_addr_list[0][2]&0x00ff),(host_entry->h_addr_list[0][3]&0x00ff));}
In this way, gethostbyname () is the system's own library function. You can resolve the domain name to the struct hostent, and then parse the struct yourself.