GithubHelp home page GithubHelp logo

Comments (13)

DevaLee avatar DevaLee commented on June 4, 2024 1

每发一次请求,Client Address的端口值都会变。
我使用 iOS原生网络请求框架 Alamofire进行网络请求时,Client Address的端口值不会变,HTTPS连接会进行持久连接,Kept Alive 值为true,TLS HandShake 值为 -

能帮我看一下,在dio中如何能 保持持久连接么?每次请求不需要重新进行 TLS 握手。

from dio.

hc79879 avatar hc79879 commented on June 4, 2024

I also encountered the same problem

from dio.

OnClickListener2048 avatar OnClickListener2048 commented on June 4, 2024

same here

from dio.

zombiu avatar zombiu commented on June 4, 2024

how to fix

from dio.

shaopx avatar shaopx commented on June 4, 2024

is this a new issue?

from dio.

shaopx avatar shaopx commented on June 4, 2024

I solve this by the following code:
HttpClient createMyHttpClient() {
return HttpClient()..idleTimeout = const Duration(seconds: 300);
}
_dio.httpClientAdapter =
IOHttpClientAdapter(createHttpClient: createMyHttpClient);

from dio.

OnClickListener2048 avatar OnClickListener2048 commented on June 4, 2024

I solve this by the following code: HttpClient createMyHttpClient() { return HttpClient()..idleTimeout = const Duration(seconds: 300); } _dio.httpClientAdapter = IOHttpClientAdapter(createHttpClient: createMyHttpClient);

thanks, but i don't know if it really works, how can i test it ?

from dio.

shaopx avatar shaopx commented on June 4, 2024

I solve this by the following code: HttpClient createMyHttpClient() { return HttpClient()..idleTimeout = const Duration(seconds: 300); } _dio.httpClientAdapter = IOHttpClientAdapter(createHttpClient: createMyHttpClient);

thanks, but i don't know if it really works, how can i test it ?

use flutter devtools --> network tab, check the connection establish time.

from dio.

AlexV525 avatar AlexV525 commented on June 4, 2024

idleTimeout corresponds to the alive time of the client. If your client got released in a short time, please consider increasing the configuration. It's also recommended to test with the dart:io:HttpClient and package:http.

from dio.

zerg000000 avatar zerg000000 commented on June 4, 2024

This is why keep-alive not working. The default idleTimeout for underlying package:http is 15 seconds. However, don't know why dio set it to 3 seconds. According to package:http documentation. The non-active connection in pool will be closed by min(idleTimeout, keep-alive timeout).

final client = HttpClient()..idleTimeout = Duration(seconds: 3);

from dio.

zerg000000 avatar zerg000000 commented on June 4, 2024

Dio 10 requests with no sleep in between

Dio 10 requests with 4s sleep in between

dart:http 10 requests with 4s sleep in between

from dio.

kuhnroyal avatar kuhnroyal commented on June 4, 2024

The HttpClient.idleTimeout of 3 seconds has already been removed on the 6.0.0 branch. The behavior will not be changed for 5.x since this is in some ways a breaking change.

from dio.

AlexV525 avatar AlexV525 commented on June 4, 2024

In order to get rid of the default 3 seconds timeout, either create a new HttpClient with a new timeout using createHttpClient or set the timeout using onHttpClientCreate (deprecated).

from dio.

Related Issues (20)

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.