-
Notifications
You must be signed in to change notification settings - Fork 14
/
get_max_retransmit.dart
48 lines (38 loc) · 1.34 KB
/
get_max_retransmit.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ignore_for_file: avoid_print
/*
* Package : Coap
* Author : S. Hamblett <[email protected]>
* Date : 06/06/2018
* Copyright : S.Hamblett
*
* Demonstrates adjustments to the retransmission configuration
*/
import 'dart:async';
import 'package:coap/coap.dart';
import './config/coap_config.dart';
FutureOr<void> main() async {
final conf = CoapConfig();
final baseUri =
Uri(scheme: 'coap', host: 'google.com', port: conf.defaultPort);
final client = CoapClient(baseUri, config: conf);
print('maxRetransmit config: ${conf.maxRetransmit}');
final request = CoapRequest.get(Uri(path: 'doesNotExist'));
print('maxRetransmit request: ${request.maxRetransmit} (0=config default)');
try {
// Override maxRetransmit for this request
request.maxRetransmit = 2;
print('maxRetransmit altered request: ${request.maxRetransmit}');
print('Sending get /doesNotExist to ${baseUri.host}');
print('Waiting for timeout, this might take a while...');
final resp = await client.send(request);
if (request.isTimedOut) {
print('Timeout! Client retransmitted ${request.retransmits} times');
} else {
print('Expected timeout did not happen, something could be wrong');
}
print('Response: $resp');
} on Exception catch (e) {
print('CoAP encountered an exception: $e');
}
client.close();
}