mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Send broadcast message to all local addresses in NetworkServiceDiscovery::Advertiser::sendBroadcast()
This commit is contained in:
parent
68b02efea1
commit
c8532775e5
1 changed files with 14 additions and 5 deletions
|
|
@ -67,11 +67,20 @@ void NetworkServiceDiscovery::Advertiser::run()
|
|||
|
||||
void NetworkServiceDiscovery::Advertiser::sendBroadcast()
|
||||
{
|
||||
auto localAddress = IPAddress::getLocalAddress();
|
||||
message.setAttribute ("address", localAddress.toString());
|
||||
auto broadcastAddress = IPAddress::getInterfaceBroadcastAddress (localAddress);
|
||||
auto data = message.toString (XmlElement::TextFormat().singleLine().withoutHeader());
|
||||
socket.write (broadcastAddress.toString(), broadcastPort, data.toRawUTF8(), (int) data.getNumBytesAsUTF8());
|
||||
static IPAddress local = IPAddress::local();
|
||||
|
||||
for (auto& address : IPAddress::getAllAddresses())
|
||||
{
|
||||
if (address == local)
|
||||
continue;
|
||||
|
||||
message.setAttribute ("address", address.toString());
|
||||
|
||||
auto broadcastAddress = IPAddress::getInterfaceBroadcastAddress (address);
|
||||
auto data = message.toString (XmlElement::TextFormat().singleLine().withoutHeader());
|
||||
|
||||
socket.write (broadcastAddress.toString(), broadcastPort, data.toRawUTF8(), (int) data.getNumBytesAsUTF8());
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue