tcp连接在TIME

编程入门 行业动态 更新时间:2024-10-23 09:32:09
本文介绍了tcp连接在TIME_WAIT将不允许重连,java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在与服务器建立tcp连接后,我关闭了我的 linux 应用程序,并调用了Socket.close()。

After making a tcp connection to a server, I close my linux application and Socket.close() is called.

检查netstat -pant,我看到连接处于TIME_WAIT状态。

Checking netstat -pant, I see the connection is in TIME_WAIT status.

这阻止我立即连接回服务器,因为我使用相同的端口连接。相反,我必须等待连接超时的TIME_WAIT状态,然后才能重新连接。

This prevents me from making an immediate connection back to the server since I'm using the same port to connect from. Instead, I have to wait for the connection to timeout of the TIME_WAIT status before I can reconnect again.

我玩过 - 没有运气 - 使用套接字方法: set_so_timeout(),set_keepalive(),set_so_linger()和set_reuseaddr() - 方法的正确拼写可能不正确在这篇文章。

I've played around -without luck- with the socket methods: set_so_timeout(), set_keepalive(), set_so_linger(), and set_reuseaddr() - exact spelling of the method may not be right in this post.

我的问题是我将连接退出TIME_WAIT状态,以便我可以立即重新建立连接?

My question is HOW do I get the connection out of the TIME_WAIT status so I can instantly make a connection again?

请让我知道。

感谢, jbu

Thanks, jbu

推荐答案

将连接从TIME_WAIT中取出的最好方法wait: - )

The best way to get the connection out of TIME_WAIT is (surprisingly) to wait :-)

这就是TCP / IP的工作原理。会话由元组(sourceIP,sourcePort,destIP,destPort,protocol)标识,并且您不能重复使用它的原因是因为可能有数据包它仍然出现在网络的某个地方。

That's how TCP/IP works. A session is identified by the tuple (sourceIP, sourcePort, destIP, destPort, protocol) and the reason why you can't re-use it is because there may be packets for it still out in the network somewhere.

TIME_WAIT状态通常是最大数据包生命周期的两倍,你应该不会导致数据包从上一个会话中显示出来(这会使您当前的会话变坏)。

TIME_WAIT state is generally twice the maximum packet lifetme and you should not be fiddling with it since that may cause packets to show up from the previous session (which will screw up your current session).

理想情况下,您应该从不同的源端口连接,立即打开会话。

Ideally, you should connect from a different source port, then you will be able to open the session immediately.

另一件你应该注意的事情是封闭会话。我一直订阅的指南,客户端应该关闭会话(并关闭它干净)。这最大限度地减少了长期半封闭式会议的可能性。

Another thing you should watch out for is badly closed sessions. I've always subscribed to the guideline that the client should shut down the session (and shut it down cleanly). This minimizes the possiblity for long-lived half-closed sessions hanging around.

更多推荐

tcp连接在TIME

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

发布评论

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

>www.elefans.com

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