Android Question Android TCP connect to multiple servers async

Discussion in 'Android Questions' started by Rusty, Jul 24, 2015.

  1. Rusty

    Rusty Well-Known Member Licensed User

    I have an Android app that needs to use TCP/Astreams/Prefix Mode to connect to a server (i.e. and then communicate a bit then disconnect and then connect to another server (i.e.

    I am having some difficulty getting it to disconnect and also re-connect. Any suggestions are appreciated. I issue a stopservice and then a startservice to re-initialize everything. I think these two events occur too fast. Is there a way to detect service destroy?
    My TCP code is a service.
  2. Erel

    Erel Administrator Staff Member Licensed User

    Stopping the service will not disconnect AsyncStreams. You should instead call AsyncStreams.Close and then create the new connection.
  3. Rusty

    Rusty Well-Known Member Licensed User

    Thanks Erel. I have been successful by leaving the service running; closing Astreams; closing the socket; changing the IP address and letting the service re-open the new IP address. Works well...even repeatedly. :)
    Once again, thanks for the guidance.
    DonManfred likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice