简体   繁体   中英

Differentiating between server threads (user connections)

I'm wondering what the best way to differentiate between server connections is. My client connection has their own thread, which I aim to put in a group with 2 other users (3 in total) kind of like a lobby.

I'm currently looking at ThreadGroup and trying to assign every 3 users to a thread group however I'm not sure this is even remotely correct, as I cannot see any clear way of then finding which users are in which thread group.

If someone could point me in the right direction it would be very helpful.

I wouldn't use a ThreadGroup for the purposes of classifications of threads. A ThreadGroup allows threads to do operations and get information about a collection of threads. I don't think you need this functionality.

I'd use one of the Collection classes to group your user or game threads together. The Collection could be inside of the custom class which you use to store the game state.

If you need to find the games that need more members then I'd have a Collection of games that need members that you add and delete from as users login/out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM