jeudi 28 avril 2016

Get answers from broadcast

I'm implementing a WSDiscovery service using Poco::Net::DatagramSocket. This is the code:

string OnvifCamera::_sendFullProbe_for_Discovery() const noexcept
{
    Poco::Net::DatagramSocket ss(Poco::Net::IPAddress::IPv4);
    Poco::Net::SocketAddress sa(global.getDiscoveryIP(), global.getDiscoveryPort()); //IP "239.255.255.250", port 3702
    try
    {
        auto msg = _createXML_for_FullProbe();//is the XML probe x discovery
        ss.sendTo(msg.data(), msg.size(), sa);
    }
    catch (const Poco::IOException& ex)
    {
        cerr<<"\nException: "<<ex.what()<<", "<<ex.displayText()<<endl;
        return string();
    }
    ss.setBroadcast(true);

    char buffer[4096];
    int n = ss.receiveBytes(buffer, sizeof(buffer));
    cout<<"Got "<<n<<" bytes"<<endl;
    ss.close();
    return string(buffer);
}

Every device (IP Onvif camera), will answer with his XML data. The problem is that if I have more cameras, I can get only 1 camera's answer. How can I get ALL the answers?

Thank you Cristiano

Aucun commentaire:

Enregistrer un commentaire