Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

experimental cronet dart bindings

this package binds to cronet’s native api to expose them in dart.

this is a gsoc 2021 project.

supported platforms

currently, 64 bit android and desktop platforms (linux, windows and macos) are supported.

requirements

  1. dart sdk 2.12.0 or above.
  2. cmake 3.10 or above. (if on windows, visual studio 2019 with c++ tools)
  3. c++ compiler. (g++/clang/msvc)
  4. android ndk if targeting android.

usage

  1. add package as a dependency in your pubspec.yaml.
  2. run this from the root of your project.
    flutter pub get
    flutter pub run cronet:setup # downloads the cronet binaries.
    

    we need to use flutter pub even if we want to use it with dart cli. see https://github.com/dart-lang/pub/issues/2606 for further details.

    *note for android: remember to add the following permissions in androidmanifest.xml file.

     <uses-permission android:name="android.permission.internet" />
     <uses-permission android:name="android.permission.access_network_state" />
    

    optionally, enable cleartext traffic by adding android:usescleartexttraffic="true" to androidmanifest.xml file.

  3. import
    import 'package:cronet/cronet.dart';
    

note: internet connection is required to download cronet binaries.

example

  final client = httpclient();
  client
      .geturl(uri.parse('http://info.cern.ch/'))
      .then((httpclientrequest request) {
    return request.close();
  }).then((httpclientresponse response) {
    response.transform(utf8.decoder).listen((contents) {
      print(contents);
    },
      ondone: () => print(
        'done!'));
  });

see the api comparison with dart:io.

run example

flutter

cd example/flutter
flutter pub get
flutter pub run cronet:setup # downloads the cronet binaries.
flutter run

dart cli

cd example/cli
flutter pub get
flutter pub run cronet:setup # downloads the cronet binaries.
dart run bin/example_dart.dart

run tests

flutter pub get
flutter pub run cronet:setup # downloads the cronet binaries.
flutter test

you can also verify your cronet binaries using dart run cronet:setup verify.
make sure to have cmake 3.10.

benchmarking

see benchmark summary and extensive reports for comparison with dart:io.

flutter pub get
flutter pub run cronet:setup # downloads the cronet binaries.
dart run benchmark/latency.dart # for sequential requests benchmark.
dart run benchmark/throughput.dart # for parallel requests benchmark.
dart run benchmark/run_all.dart # to run all the benchmarks and get reports.

use -h to see available cli arguments and usage informations.

to know how to setup local test servers, read benchmarking guide.

note: test results may get affected by: https://github.com/google/cronet.dart/issues/11.

building your own

  1. make sure you’ve downloaded your custom version of cronet shared library and filename follows the pattern cronet.86.0.4240.198.<extension> with a prefix lib if on linux. else, you can build cronet from source using the provided instuctions. then copy the library to the designated folder. for linux, the files are under .dart_tool/cronet/linux64.
  2. run dart run cronet:setup build from the root of your project.

note for windows: run step 2 from x64 native tools command prompt for vs 2019 shell.

note for android: copy the produced jar files in android/libs and .so files in android/src/main/jnilibs subdirectory from the root of this package.


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.