JsonRPC/examples/Dart/Test.dart

43 lines
921 B
Dart

import 'dart:async';
import 'dart:io';
import "./out/lib/example.dart";
import "dart:convert";
void main() async {
var str = StreamController<Map<String, dynamic>>();
var provider = ServiceProvider(str.stream);
var sock = await Socket.connect("127.0.0.1", 8859);
utf8.decoder.bind(sock).transform(new LineSplitter()).listen((line) {
str.add(jsonDecode(line));
});
provider.output.stream.listen((event) {
sock.writeln(jsonEncode(event));
});
var s = new TestServiceClient(provider);
var r = await s.AddValuesMultipleParams(10, 15);
print(r);
var r2 =
await s.AddValuesSingleParam(AddValueRequest(value1: 10, value2: 15));
print(r2?.value);
var catched = false;
await s.ThrowingError().catchError((err) {
catched = true;
print("Expected error was catched: " + err.toString());
});
if (!catched) {
throw Error();
}
await sock.close();
// exit(0);
}