2 Star 0 Fork 0

mirrors_google / cronet.dart

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause

⚠️ This project has been superseeded by https://pub.dev/packages/cronet_http.

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 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.

Copyright 2021, the Dart project authors. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

暂无描述 展开 收起
Dart
BSD-3-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_google/cronet.dart.git
git@gitee.com:mirrors_google/cronet.dart.git
mirrors_google
cronet.dart
cronet.dart
main

搜索帮助

344bd9b3 5694891 D2dac590 5694891