Tcp常见配置参数说明

发布时间 2023-11-23 11:51:08作者: 软件匠工
socket = new Socket();
//TIME_WAIT状态下可以复用端口
socket.setReuseAddress(true);
//空闲时发送数据包,确认服务端状态
socket.setKeepAlive(true);
//关闭Nagle算法,尽快发送
socket.setTcpNoDelay(true);
//调用close方法立即关闭socket,丢弃所有未发送的数据包
socket.setSoLinger(true, 0);
//连接server
socket.connect(new InetSocketAddress(host, port), connectionTimeout);
//设置读取时超时时间
socket.setSoTimeout(soTimeout);