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?
You're only calling receiveBytes
once, so that's why you only get one answer.
To receive the multiple individual answers you'll need to call receiveBytes
repeatedly, and most likely implement a timeout after which you give up waiting for any more responses to be received (since you can't know apriori how many there'll be).