Cnet高性能网络堆栈
Cnet 是一个易于使用的 Chromium HTTP 高性能网络堆栈和文件缓存开发包。它支持 Chromium的 SPDY 和 QUIC 。
Cnet 上有 C 语言和 Java 语言的绑定。完整的 Java API 请参见 android/java 。若要查看完整的 C API 请查看 cnet.h
。此应用程序可以同时使用 Java 和 C 语言绑定。
Java Fetch 示例:
// Initialize the library.final Context appContext = getApplicationContext();Cnet.loadLibraries(appContext);Cnet.initLibraryOnUiThread(appContext);// Establish a Cnet Pool for connection reuse.final CnetPool.Config poolConfig = new CnetPool.Config(); poolConfig.userAgent = "cnet-test"; poolConfig.enableSpdy = true; poolConfig.enableSslFalseStart = true;final CnetPool pool = new CnetPool(poolConfig);// Create an HTTP request.final Fetcher fetcher = pool.createFetcher("https://yahoo.com", "GET", new ResponseCompletion() { @Override public boolean onBackgroundComplete(Fetcher fetcher, Response response) { Log.d(LOG_TAG, "request completed, " + response.getHttpResponseCode() + ", " + response.getOriginalUrl() + ", " + response.getFinalUrl() + ", " + response.getBodyLength() + ", " + (new String(response.getBody()))); return RELEASE_NOW; // immediately release native resources } }); fetcher.start();
评论