Android Question multiple socket management best practice

sorex

Expert
Licensed User
Longtime User
Hello,

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?
 

sorex

Expert
Licensed User
Longtime User
@Erel

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. :(
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime 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).
 

Attachments

  • MultipleSockets.zip
    22.9 KB · Views: 362
Upvote 0

sorex

Expert
Licensed User
Longtime 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.

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:
Upvote 0
Top