Skip to content

Commit

Permalink
feat: add example for sendMulticast method
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Aug 17, 2022
1 parent e8b6f17 commit 61a1a16
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions example/get_resource_multicast.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// ignore_for_file: avoid_print

/*
* Package : Coap
* Author : S. Hamblett <steve.hamblett@linux.com>
* Date : 06/06/2018
* Copyright : S.Hamblett
*
* Example for iterating over responses using sendMulticast().
*
* For this to work, you need at least one CoAP node reachable under the
* link-local IPv6 "All CoAP nodes" multicast address (ff02::fd), exposing its
* resources using `/.well-known/core`.
*/

import 'dart:async';
import 'package:coap/coap.dart';
import 'config/coap_config.dart';

FutureOr<void> main() async {
final conf = CoapConfig();
final uri = Uri(
scheme: 'coap',
host: CoapDefinedAddress.allCOAPNodesLinkLocalIPV6,
port: conf.defaultPort,
);
final client = CoapClient(uri, conf);

try {
final request = CoapRequest.newGet()..uriPath = './well-known/core';

await for (final response in client.sendMulticast(request)) {
print(response.payloadString);
break;
}
} on Exception catch (e) {
print('CoAP encountered an exception: $e');
}

client.close();
}

0 comments on commit 61a1a16

Please sign in to comment.