ensureInitiaLized method
Future<void>
ensureInitiaLized({
- required RawDatagramSocket socket,
- required NetworkInterface networkInterface,
- required FutureOr<
void> onMessage(- GeneralSocketMessageData generalSocketMessageData
- required void onDone(),
Implementation
Future<void> ensureInitiaLized({
required RawDatagramSocket socket,
required NetworkInterface networkInterface,
required FutureOr<void> Function(
GeneralSocketMessageData generalSocketMessageData)
onMessage,
required void Function() onDone,
}) async {
if (is_initialized) {
return;
}
_socket = socket;
socket.joinMulticast(
InternetAddress(multiCastGroup),
networkInterface,
);
socket.listen(
(e) async {
final Datagram? datagram = socket.receive();
if (datagram == null) {
return;
}
onMessage(GeneralSocketMessageData(
socket_id: socket_id,
ipAddres: datagram.address.address,
data: datagram.data,
));
},
onDone: () {
onDone();
},
);
is_initialized = true;
}