bool ThreadObject::checkIP(QString host)
{
//判断IP地址合法性
QStringList ipsplit = host.split('.');
//判断是否为111.111.111.111的形式
if(ipsplit.length() !=4)
return false;
for(int n=0;n<4;n++)
{
//判断每一段的数字范围(含非数字时,toInt也为0)
if(ipsplit[n].length()==0 || ipsplit[n].length()>3 || ipsplit[n].toInt()<0 || ipsplit[n].toInt()>255)
return false;
//判断是否都为数字
for(int m=0;m<ipsplit[n].length();m++)
{
if(!(ipsplit[n].at(m)>=QChar('0') && ipsplit[n].at(m)<=QChar('9')))
return false;
}
}
return true;
}
//使用gethostbyname 通过域名获知ip地址 / 直接使用IP地址
int ThreadObject::netConnect(const char *host,u_short port)
{