void SSDP::PerformSearch( const QString &sST ) { QString rRequest = QString( "M-SEARCH * HTTP/1.1\r\n" "HOST: 239.255.255.250:1900\r\n" "MAN: \"ssdp:discover\"\r\n" "MX: 2\r\n" "ST: %1\r\n" "\r\n" ).arg( sST ); QByteArray sRequest = rRequest.toUtf8(); MSocketDevice *pSocket = m_Sockets[ SocketIdx_Search ]; if ( !pSocket->isValid() ) { pSocket->setProtocol(MSocketDevice::IPv4); pSocket->setSocket(pSocket->createNewSocket(), MSocketDevice::Datagram); } QHostAddress address; address.setAddress( SSDP_GROUP ); int nSize = sRequest.size(); if ( pSocket->writeBlock( sRequest.data(), sRequest.size(), address, SSDP_PORT ) != nSize) cerr << "SSDP::PerformSearch - did not write entire buffer." << endl; usleep( rand() % 250000 ); if ( pSocket->writeBlock( sRequest.data(), sRequest.size(), address, SSDP_PORT ) != nSize) cerr << "SSDP::PerformSearch - did not write entire buffer." << endl; }
void SSDP::PerformSearch(const QString &sST, uint timeout_secs) { timeout_secs = std::max(std::min(timeout_secs, 5U), 1U); QString rRequest = QString("M-SEARCH * HTTP/1.1\r\n" "HOST: 239.255.255.250:1900\r\n" "MAN: \"ssdp:discover\"\r\n" "MX: %1\r\n" "ST: %2\r\n" "\r\n") .arg(timeout_secs).arg(sST); LOG(VB_UPNP, LOG_DEBUG, QString("\n\n%1\n").arg(rRequest)); QByteArray sRequest = rRequest.toUtf8(); MSocketDevice *pSocket = m_Sockets[ SocketIdx_Search ]; if ( !pSocket->isValid() ) { pSocket->setProtocol(MSocketDevice::IPv4); pSocket->setSocket(pSocket->createNewSocket(), MSocketDevice::Datagram); } QHostAddress address; address.setAddress( SSDP_GROUP ); int nSize = sRequest.size(); if ( pSocket->writeBlock( sRequest.data(), sRequest.size(), address, SSDP_PORT ) != nSize) LOG(VB_GENERAL, LOG_INFO, "SSDP::PerformSearch - did not write entire buffer."); usleep( random() % 250000 ); if ( pSocket->writeBlock( sRequest.data(), sRequest.size(), address, SSDP_PORT ) != nSize) LOG(VB_GENERAL, LOG_INFO, "SSDP::PerformSearch - did not write entire buffer."); }