GithubHelp home page GithubHelp logo

aam / cronet.dart Goto Github PK

View Code? Open in Web Editor NEW

This project forked from google/cronet.dart

0.0 0.0 0.0 253 KB

This package binds to Cronet's native API to expose them in Dart.

Home Page: https://pub.dev/packages/cronet

License: BSD 3-Clause "New" or "Revised" License

Dart 58.46% CMake 9.16% C++ 22.89% C 4.02% HTML 0.62% Python 1.84% Kotlin 0.84% Ruby 1.38% Objective-C 0.41% Objective-C++ 0.38%

cronet.dart's Introduction

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, Mobile and Desktop Platforms (Linux, Windows and MacOS*) are supported.

*MacOS is supported in Dart CLI platform only. Flutter compatible version coming soon.

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 dart-lang/pub#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: google#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.

cronet.dart's People

Contributors

dcharkes avatar mannprerak2 avatar unsuitable001 avatar zhileichen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.