send method

  1. @override
void send(
  1. Iterable<FullAddress> fullAddresses,
  2. Uint8List datagram
)
override

Sends a datagram to the specified addresses.

This method sends a datagram to the specified addresses using the underlying UDP socket. It iterates over the provided addresses and sends the datagram to each one, skipping empty or incompatible addresses.

fullAddresses An iterable of FullAddress objects representing the destinations to send the datagram to. datagram The datagram data to be sent.

Implementation

@override
void send(
  Iterable<FullAddress> fullAddresses,
  Uint8List datagram,
) {
  // If the socket is not initialized, do nothing.
  if (_socket == null) {
    return;
  }

  // Iterate over the provided addresses and send the datagram to each one.
  for (final peerFullAddress in fullAddresses) {
    // Skip empty or incompatible addresses.
    if (peerFullAddress.isEmpty) {
      continue;
    }
    if (peerFullAddress.type != bindAddress.type) {
      continue;
    }

    try {
      // Send the datagram using the underlying socket.
      _socket?.send(datagram, peerFullAddress.address, peerFullAddress.port);
    } on Object catch (e) {
      // Log any errors that occur during sending.
      logger?.call(e.toString());
    }
  }
}