setSoTimeout(0); // HTTP/2 connection timeouts are set per-stream. http2Connection = new Http2Connection.Builder(true) .socket(socket, route.address().url().host(), source, sink) .listener(this) .build(); http2Connection.start(); } } 这时候我们在回来看下findConnection()方法里面的...
socket.setSoTimeout(0);// Framed connection timeouts are set per-stream.Http2Connection http2Connection =newHttp2Connection.Builder(true) .socket(socket, route.address().url().host(), source, sink) .listener(this) .build(); http2Connection.start();// Only assign the framed connection once...
publicHttpStreamnewStream(OkHttpClient client,booleandoExtensiveHealthChecks){//得到连接时长、读超时以及写超时参数intconnectTimeout=client.connectTimeoutMillis();intreadTimeout=client.readTimeoutMillis();intwriteTimeout=client.writeTimeoutMillis();booleanconnectionRetryEnabled=client.retryOnConnectionFailure(...
直接创建OkHttpClient实例,配置项就是Builder构造方法中默认值。可见配置项是非常多的,包括上一篇中已经使用过的超时设置、拦截器。 接着看Request的创建,也是使用建造者模式: 代码语言:javascript 复制 publicBuilder(){this.method="GET";this.headers=newHeaders.Builder();}publicBuilderget(){returnmethod("GET",...
=null){//建立TLS连接,看看哪些情况需要建立TLS连接connectTls(readTimeout,writeTimeout,connectionSpecSelector);}else{//不需要建立TLS连接的,统一当做HTTP 1.1协议protocol=Protocol.HTTP_1_1;socket=rawSocket;}if(protocol==Protocol.SPDY_3||protocol==Protocol.HTTP_2){socket.setSoTimeout(0);// Framed ...
("https://api.github.com/markdown/raw") .post(RequestBody.create(MEDIA_TYPE_MARKDOWN, file)) .build(); Response response = client.newCall(request).execute(); if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); System.out.println(response.body().string()...
try{listener.onOpen(RealWebSocket.this,response);String name="OkHttp WebSocket "+request.url().redact();initReaderAndWriter(name,pingIntervalMillis,streams);streamAllocation.connection().socket().setSoTimeout(0);loopReader();}catch(Exceptione){failWebSocket(e,null);}} ...
同时,在 HTTP/1.1 中还引入了Keep-Alive请求头,在其中可以设定两个值:timeout与max,从而设定这个连接何时被关闭。 timeout:指定了一个空闲连接需要保持打开状态的最小时长(以秒为单位) max:在连接关闭之前,在此连接可以发送的请求的最大值 但这样就存在了一个问题,在原来不采用Keep-Alive的时候,客户端可以通过...
(request);try{Responseresponse=call.execute();ResponseBodyresponseBody=response.body();System.out.println(responseBody.string());}catch(IOExceptione){e.printStackTrace();}call.enqueue(newCallback(){@OverridepublicvoidonFailure(Callcall,IOExceptione){}@OverridepublicvoidonResponse(Callcall,Response...
transmitter.timeoutEnter(); transmitter.callStart(); try { // 从okHttpClient中取出分发器调用executed client.dispatcher().executed(this); // 直接调用RealCall的拦截器 执行流程后面会讲到 return getResponseWithInterceptorChain(); } finally {