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. 192.168.1.1) and then communicate a bit then disconnect and then connect to another server (i.e. 192.168.1.2).

    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.
    Thanks,
    Rusty
     
  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.
    Rusty
     
    DonManfred likes this.
Loading...