方案1
//bool tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port );//失败 没指定 是IPV4还是IPV6
方案2
// QString string("192.168.112.10");
// QHostAddress address(QHostAddress::LocalHost);//QHostAddress::Any
// bool tf =address.setAddress( string );
// tf =m_pSocket->bind(address,m_port );//失败
方案3
// quint32 ip4Add = 192<<24|168<<16|112<<8|10;
// QHostAddress address(QHostAddress::Any);//QHostAddress::LocalHost
// address.setAddress( ip4Add );
// bool tf =m_pSocket->bind(address,m_port );//失败
方案4
//tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port,QAbstractSocket::ReuseAddressHint| QAbstractSocket::ShareAddress | QAbstractSocket::DontShareAddress );//失败
//tf =m_pSocket->bind(QHostAddress(ip4Add),m_port,QAbstractSocket::ReuseAddressHint| QAbstractSocket::ShareAddress | QAbstractSocket::DontShareAddress );
这共享和非共享明显时互斥的,这为啥这样测试 忘了
其他方案
//quint32 ip4Add = 192<<24|168<<16|112<<8|100;
//bool tf =m_pSocket->bind(QHostAddress(ip4Add),m_port,QAbstractSocket::ShareAddress );
// tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port,QAbstractSocket::ReuseAddressHint );
// tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port,QAbstractSocket::ShareAddress );
// tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port,QAbstractSocket::DontShareAddress );
//tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port,QAbstractSocket::ReuseAddressHint | QAbstractSocket::ShareAddress );
//tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port,QAbstractSocket::DontShareAddress | QAbstractSocket::ReuseAddressHint );
//tf =m_pSocket->bind(QHostAddress("192.168.112.100"),m_port,QAbstractSocket::DontShareAddress | QAbstractSocket::ShareAddress );
//m_pSocket->bind(QHostAddress::Any, m_port );//方便使用