0

I'm creating a chat application in Android using NSD(Network service disovery) .
My question is how to reconnect Client with previous Client ip and port.
Example : Client ip and port when it connects to server first time
port:52354
IP:110.100.92.187
Suppose if somehow connection is lost so can i reconnect to server with same IP and PORT i.e. port:52354
IP:110.100.92.187
or any other way to make code reliable so that it won't loose connection ?remember i'm using NSD for Local network(local wifi network and hotspot) not for internet.
Any other better solution for this problem is most welcome.

1 Answers1

0

how to reconnect Client with previous Client ip and port

In general you can't, because of the TCP TIME_WAIT state. This means that you can't reuse the same local port for two minutes or whatever twice the locally configured Maximum Segment Lifetime (MSL) is. If you can wait that long you can bind() the socket to that port prior to connecting it.

In practice you shouldn't rely on IP:port as a client identifier.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • "This means that you can't reuse the same local port for two minutes" does it mean if device is remain connected for two minutes it will automatically reset after two minutes ??? – Ankur Singh Mar 10 '17 at 10:34