当有符合国家'TCP连接不能建立TCP连接TIME

编程入门 行业动态 更新时间:2024-10-23 15:33:03
本文介绍了当有符合国家'TCP连接不能建立TCP连接TIME_WAIT`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我写了一个简单的TCP客户端和服务器跑他们我注意到,当我使用 CTRL + C 来结束该程序TCP连接将被关闭但TCP连接状态就像 TIME_WAIT 那么,如果我再次运行TCP客户机和服务器TCP连接不能被再次建立一个 RST 包总是由TCP服务器发送我必须等待一段时间,直到下一个TCP连接建立

I wrote a simple tcp client and server and ran them I notice that when I use ctrl+c to end the program the tcp connection be be closed but the tcp connection state is like TIME_WAIT then if I run the tcp client and server again the tcp connection can't be established again a RST packet is always sent by the tcp server I have to wait for some time until the next tcp connection can be established

是什么,这和如何的原因来处理这个问题?

what is the reason for this and how to deal with this problem?

,我发现一台主机上,当一个TCP连接的状态为 FIN_WAIT_2 即使没有收到 FIN ,TCP连接将成为后就关闭了一段时间为什么?

besides, I notice on one host, when a tcp connection is in state FIN_WAIT_2 even if it doesn't receive FIN, the tcp connection will become closed some time later ,why?

感谢

推荐答案

有关这个问题的解决办法是设置SO_REUSEADDR套接字选项。这告诉协议栈允许上碰巧处于TIME_WAIT状态地址绑定。

The solution for this problem is to set the SO_REUSEADDR socket option. This tells the stack to allow a bind on addresses that happen to be in the TIME_WAIT state.

原因TIME_WAIT状态似乎让一些时间失散的数据包到达。如果堆栈无法确保连接是正常关机,有可能在运输途中或发送数据包甚至可以主动发送更多数据。堆栈要避免这些数据包与新绑定连接的流量混合。

The reason for the TIME_WAIT state seems to be to allow some time for the straggler packets to arrive. If the stack cannot make sure that the connection was shutdown gracefully, there maybe packets in transit or the sender may even be sending more data actively. The stack wants to avoid mixing these packets with the traffic of a newly bound connection.

下面是关于使用SO_REUSEADDR的TCP和UDP一个很好的答案。

Here is a good answer on the use of SO_REUSEADDR for TCP and UDP.

更多推荐

当有符合国家'TCP连接不能建立TCP连接TIME

本文发布于:2023-11-13 00:06:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582857.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:符合国家   TIME   TCP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!