1

I'm working on a personal project on android where a client and server keep sharing each other's location through a TCP connection . it's working fine however as we know TCP connections break when you change IP address. How can I reopen the socket as soon as it closes?

is there any other connection type that I can use?

is it sufficient to change Ip from Dynamic to static?

Mohamad
  • 11
  • 2
  • Don't you get some kind of exception when the connection terminates? I guess IOException is thrown in such case. See: https://stackoverflow.com/questions/151590/how-to-detect-a-remote-side-socket-close – Endre Börcsök Jun 12 '17 at 17:41

2 Answers2

0

you have to change IP address Dynamic to static, this is the one way to resolve your problem and you can also use Hostname to create connection. but static ip is better solution for this problem.

Anshul Sharma
  • 3,432
  • 1
  • 12
  • 17
0

Typically, you will get a SocketException (a subclass of IOException) when the connection closes if you are waiting on InputStream.read(...); this is where you should do your reconnect (from the client)

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80