Android Question multiple socket management best practice

Discussion in 'Android Questions' started by sorex, Feb 12, 2015.

  1. sorex

    sorex Expert Licensed User


    Does anyone know how I can work with multiple sockets and have the ability to loop through them?

    Can I store that with IP etc into a map/list ?

    And how would I know what to remove from that map/list when a socket disconnects?
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. sorex

    sorex Expert Licensed User


    thanks, I missed this reply.

    the problem is that my system works the other way around.

    In your example the phones connect to your server, in my case the server connects to the phone so i'm limited to socket connect that only gives a successful status back. :(
  4. Erel

    Erel Administrator Staff Member Licensed User

    It doesn't matter. The important part is to manage the multiple AsyncStreams correctly.
  5. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed User

    I'm not sure about the "correct" way, but here is a little test chat program I wrote that lets multiple clients connect to a phone acting as a server and it seems to work fine.

    I based the socket handling on the camera example, however, I did notice that the AsyncStreams Terminated event never seems to fire so I built in a sanity check to watch for disconnected clients.

    It's one main service that runs both server and client modes (you decide which to run after starting the service).

    Attached Files:

  6. sorex

    sorex Expert Licensed User

    It's like you wrote, phones connect to the server.

    In my case the phones sent their info (ip, name, type) to a middle ware server
    (as there will be more than one "listening" device)
    and the "receiver/listening" tablet pulls that info in.

    Then when you click a button it opens a stream to the selected phone.

    I'll investigate the code, thanks!
    Last edited: Feb 18, 2015
  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