-
Notifications
You must be signed in to change notification settings - Fork 14
/
multi_client.dart
44 lines (37 loc) · 1.13 KB
/
multi_client.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
// ignore_for_file: avoid_print
/*
* Package : Coap
* Author : S. Hamblett <[email protected]>
* Date : 06/06/2018
* Copyright : S.Hamblett
*
* Multiple clients used in the same application
*/
import 'dart:async';
import 'package:coap/coap.dart';
import 'config/coap_config.dart';
FutureOr<void> main() async {
final conf1 = CoapConfig();
final uri1 = Uri(scheme: 'coap', host: 'coap.me', port: conf1.defaultPort);
final client1 = CoapClient(uri1, config: conf1);
final conf2 = CoapConfig();
final uri2 = Uri(
scheme: 'coap',
host: 'californium.eclipseprojects.io',
port: conf2.defaultPort,
);
final client2 = CoapClient(uri2, config: conf2);
try {
print('Sending get /hello to ${uri1.host}');
var response = await client1.get(Uri(path: 'hello'));
print('/hello response: ${response.payloadString}');
print('Sending get /test to ${uri2.host}');
response = await client2.get(Uri(path: 'test'));
print('/test response: ${response.payloadString}');
} on Exception catch (e) {
print('CoAP encountered an exception: $e');
}
// Clean up
client1.close();
client2.close();
}