broadcast method
Send a broadcast using either the multicast group for unreliable and the connected client sockets for reliable broadcast
Implementation
Future<void> broadcast(Packet packet, {bool reliable = false}) async{
bool isReady = await ready;
if( !isReady )
throw "Host failed to start";
else if( _ipAddress == null )
throw "Unable to detect host IP address";
else if( _multicastSocket != null && !reliable ){ // multicast broadcast
for( RawDatagramSocket s in _multicastSockets ){
s.send(
packet.bytes,
_ipAddress.contains(".") ?
InternetAddress(_ipAddress.split(".").sublist(0, 3).join(".") + ".255") :
_multicastGroupIP,
_multicastPort
);
}
}
else if( _serverSocket != null && reliable ){ // reliable broadcast
// send reliable broadcast using all connected client sockets
for(Device device in _discoveredDevices)
send(packet, device, ignoreIfNotConnected: true);
}
}