Reputation: 1243
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 ?
Upvotes: 1
Views: 700
Reputation: 596652
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.
Upvotes: 1
Reputation: 91059
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.
Upvotes: 1
Reputation: 4364
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.
Upvotes: 1
Reputation: 310957
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.
Upvotes: 0
Reputation: 409206
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.
Upvotes: 2