当客户端机器的 IP 发生变化时,TCP 接收行为是什么?
客户端计算机 IP 地址的更改或任何其他修改是否会影响客户端计算机中的 recv()
调用?
在服务器端没有进行任何更改。
在客户端 TCP recv()
将超时 [120 秒]。这是为什么?
如果创建套接字后客户端的 IP 发生变化,recv()
是否会超时?
操作系统:客户端和服务器都是solaris
请让我知道有关此的更多详细信息。
我认为客户端的接收超时是因为 IP 更改,但不确定。
我想知道是否有任何可用的日志消息或任何其他方法来查找原因 recv 超时 120 秒?
Does the change of the IP address of a client machine, or any other modification, affect the recv()
call in the client machine?
In the server side no changes are made.
At the client side TCP recv()
will timeout [120 second]. Why is that?
If the IP of the client chages after creating the socket, does recv()
time out?
OS: client and server both solaris
Please let me knwo more details about this.
I think recv timeout at client side because of IP changed but not sure.
I want to know is any log message available or any otehr ways to find why recv timeout afetr 120 second ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
连接由两个端点来标识,TCP/IP 中的端点是 ip 地址和端口号的组合。如果四个(两个 IP 地址和两个端口)之一发生更改,则连接不再有效。换句话说,如果客户端计算机的 IP 地址发生了更改,程序中的旧套接字仍然认为它是旧的 IP 地址,并且服务器也将具有旧的 IP 地址。
在您的程序中,在出现错误时关闭旧连接(实际上是任何错误)并重新连接到服务器。
A connection is identified by the two end-points, and an endpoint in TCP/IP is a combination of ip-address and port number. If one of the four (two ip-addresses and two ports) changes, then the connection is not valid anymore. In other words, if the client machine has its ip-address changed, the old socket in your program still thinks it's the old ip-address, and the server will also have the old ip-address.
In your program, close the old connection on error (any error really) and reconnect to the server.
当您更改客户端的 IP 地址时,来自服务器的 IP 数据包不再传递到客户端:毕竟它们是针对另一个地址的。由于没有收到任何数据包,并且所有从新地址发送的数据包不属于任何连接并被丢弃,TCP 连接最终会因 RST 数据包而超时或丢弃。
您唯一的选择是重新建立连接,无法通知 TCP 对等方地址更改。
When you change IP address of client, IP packets from server no longer delivered to client: they are for another address, after all. Since no packets are received, and all packets sent from new address do not belong to any connection and being dropped, TCP connection eventually times out or dropped because of RST packet.
Your only option is to reestablish connection, there is no way to notify TCP peer about address change.
在 TCP 中,连接由元组(源地址、源端口、目标地址、目标端口)标识。如果其中一台设备的 IP 地址发生变化,导致旧设备被删除,则连接将无法持续。
由于已建立连接的双方通过这些方式彼此分离,因此它们不会从另一方接收任何内容。所以连接最终会超时。
(在 IPv6 中,有可能添加一个新地址而不删除另一个地址;也许在 IPv4 中也是如此,我不确定这一点。)
在 UDP 中,如果地址发生变化并且发送者不知道它,消息显然无法发送。
In TCP, a connection is identified by the tuple (source address, source port, dest address, dest port). If the IP address of one of the devices changes in a way that the old one is removed, the connection cannot persist.
As both sides of the established connection are separated from each other by these means, they don't receive anything from the other side. So the connection will eventually time out.
(In IPv6, it is possible that a new address is added wothout removing the other; maybe as well in IPv4, I'm not sure abuot that.)
In UDP, if the address changes and the sender doesn't know about it, the message obviously cannot be sent.
没有什么可以告诉您为什么会发生超时,只是超时确实发生了。您需要通过读取或写入来访问连接,以检测连接的状态。如果 IP 发生变化,旧的连接现在无效,并且
recv()
应该报告错误,而不是超时。There is nothing to tell you why a timeout occurs, only that a timeout did occur. You need to access the connection, either by reading or writing, to detect the connection's state. If the IP changes, the old connection is now invalid, and
recv()
should be reporting an error, not a timeout.很难说。这取决于 IP 地址已更改的计算机上发生的情况。如果它继续将连接上的传入数据识别为有效的传入连接(如 5 元组 {tcp、本地 IP、本地端口、远程 IP、远程端口} 所定义),那么您很幸运,否则就不幸运。
Hard to say. It depends on what happens at the machine whose IP address has changed. If it continues to recognize incoming data on the connection as being for a valid incoming connection, as defined by the 5-tuple {tcp,local IP,local port, remote IP,remote port}, you're in luck, otherwise not.