OKHTTP3 Brief Introduction

Source: Internet
Author: User

Okhttp is an efficient HTTP client with the following features:

    1. Support Http2/spdy Black Technology
    2. The socket automatically selects the best route and supports automatic re-connection
    3. A socket connection pool with automatic maintenance reduces the number of handshakes
    4. With queue thread pool, easily write concurrency
    5. Have interceptors easily handle requests and responses (such as transparent gzip compression, LOGGING)
    6. Headers-based Cache policy

Note: What is spdy:http://baike.baidu.com/link?url=ybgdky_0rzcfbxkj2zy3r46ior60b62w_2- K9nf8wfrkb3zsttjhl8dqjzrun1hezxiaaw9mkpqpwjwgfoe_uq

SPDY (read as "SPeeDY") is a TCP-based transport layer protocol developed by Google to minimize network latency, improve network speed, and optimize the user experience of network usage. Spdy is not a protocol to replace HTTP, but an enhancement to the HTTP protocol. Features of the new protocol include multiplexing of data streams, request prioritization, and HTTP header compression. Google said that after the introduction of the Spdy protocol, the page was loaded faster than the original 64% in lab testing. Chinese name: spdy agreement, the current spdy has been replaced by HTTP/2, Google has announced the removal of Spdy; main object
    • Connections: A reference-count wrapper for sockets in the JDK to control the socket connection
    • Streams: A stream that maintains HTTP for IO operations on Requset/response
    • Calls:http Request Task Encapsulation
    • Streamallocation: Connections Streams Resource allocation and release for control/

Overview of Workflow

When we use OkHttpClient.newCall(request) execute/enenqueue it, we actually put the request Call Dispatcher in, Okhttp uses dispatcher for thread distribution, it has two methods, one is normal synchronous single thread, and the other is the distribution of concurrent tasks using queues (Dispatch And callback, we mainly analyze the second, that is, the queue, which is okhttp can compete with other libraries of one of the core functions;

Socket Management (streamallocation)

After the previous allocation, we now need to connect. We currently have a packaged request, while an HTTP connection requires a socket handshake, the socket handshake is based on the domain name or proxy to determine the socket IP and port. This link mainly talk about the handshake process and the management of the connection pool, the main object of the analysis isStreamAllocation

OKHTTP3 Brief Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.