FChen的408学习日记--三次握手和四次握手

一、三次握手

在这里插入图片描述
在建立连接的过程中,首先SYN=1,随机发送sqe=x。服务器接受后要反过来对客户端发送连接请求,SYN=1,随机发送sqe=y,ack=x+1·。然后客户端还要发送连接确认报文,原因如下
在这里插入图片描述
例题:
在这里插入图片描述
在这里插入图片描述

二、四次握手

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在使用RestTemplate时,可以通过设置ClientHttpRequestFactory来配置线程池。可以将RestTemplate注入到spring上下文中,并在注入时设置ClientHttpRequestFactory。以下是一个示例代码: ```java @Bean public RestTemplate restTemplate(HttpClientPoolConfig httpClientPoolConfig){ return new RestTemplate(httpClientPoolConfig.httpRequestFactory()); } ``` 其中,httpClientPoolConfig是一个自定义的配置类,用于设置HttpClient的连接池参数。在该配置类中,可以设置连接池的最大大小、每个路由的最大连接数等参数。以下是一个示例常量类的代码: ```java package com.fchen.usercenter.config; import lombok.Data; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component @Data public class HttpPoolConstants { @Value("${httpPool.restTemplateCharset:utf-8}") private String restTemplateCharset; @Value("${httpPool.poolMaxSize:500}") private Integer poolMaxSize; @Value("${httpPool.maxPerRoute:50}") private Integer maxPerRoute; @Value("${httpPool.requestConfig.socketTimeout:10000}") private Integer socketTimeout; @Value("${httpPool.requestConfig.connectTimeout:5000}") private Integer connectTimeout; @Value("${httpPool.requestConfig.connectionRequestTimeout:1000}") private Integer connectionRequestTimeout; @Value("${httpPool.maxIdleTime:5000}") private Integer maxIdleTime; @Value("${httpPool.defaultKeepAliveTime:10000}") private Integer defaultKeepAliveTime; @Value("${httpPool.specialKeepAliveTimeHostName:''}") private String specialKeepAliveTimeHostName; } ``` 在上述代码中,可以根据实际需求设置各种超时时间和连接池参数。例如,可以设置连接超时时间、读取超时时间、连接请求超时时间等。可以根据具体的业务需求,单独针对某一个URL请求设置不同的超时时间。以下是一个设置请求超时时间的示例代码: ```java private void setRequestConfig(HttpPost httpPost) { RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(this.socketTimeout) .setSocketTimeout(this.socketTimeout) .setConnectionRequestTimeout(this.connectionRequestTimeout) .build(); httpPost.setConfig(requestConfig); } ``` 通过以上配置,可以实现在RestTemplate中设置线程池和各种超时时间的功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值