Kind of, but you need to use a database rather than a dictionary to make sure state is shared properly. If you have one table called users with columns (id, username, reply_channel) and another called pairings with (user1_id, user2_id), then when someone connects, you can:
a) Add them to the users table b) If there is at least one user in the users table that is not in the pairings table, pick that user and pair it with the one connecting c) If not, wait for someone else to come along and do (b) That's a very simplistic version - you would also need cleanup for when people disconnect (you need to remove them from users and unpair them from their partner so they can be re-paired if you want) but that's the basic structure. Andrew On Sat, Jan 14, 2017 at 1:59 PM, Nikoleta Misheva <nithe...@gmail.com> wrote: > Would it be a good idea to add everyone that has an open connection to a > list of dictionaries and when 2 people are connected to remove them from > the list? And how can I guarantee that the channels limit is just 2 and > there won't be anyone joining by mistake? Or I just didn't get your idea. > Thanks for the spent time :) > > събота, 14 януари 2017 г., 22:51:59 UTC+2, Andrew Godwin написа: >> >> Your best bet is probably to use a database to track who's currently got >> an open connection and their reply channel, and then use database rows to >> match pairs together (in another table). >> >> Your message received code can then look up the other side in the table >> and forward it to that reply channel. I don't think groups would help too >> much here. >> >> Andrew >> >> On 14 Jan 2017 12:41, "Nikoleta Misheva" <nith...@gmail.com> wrote: >> >>> Hello fellows, I started to go into channels and I saw the example for >>> multiplex chat but it is not excactly what I want and I will be happy if >>> someone can point me in the right direction or show me an example. >>> So I want to have many dynamically created rooms than will be destroyed >>> after the session which the multiplexing example here >>> <https://github.com/andrewgodwin/channels-examples/tree/master/multichat> >>> takes >>> care of. But want I specifically want to do is to have only 2 people in a >>> room randomly matched and connected. >>> >>> *Here is an example: * >>> User1 clicks a button and user2 clicks the button too and so they are in >>> something like a list with people that are online, then I randomly pick the >>> 2 of them to connect to each other in a private room only for them which >>> will be destroyed when they left >>> >>> Thank you in advance >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Django users" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to django-users...@googlegroups.com. >>> To post to this group, send email to django...@googlegroups.com. >>> Visit this group at https://groups.google.com/group/django-users. >>> To view this discussion on the web visit https://groups.google.com/d/ms >>> gid/django-users/fae01772-7a30-4552-a104-0e5f519733de%40googlegroups.com >>> <https://groups.google.com/d/msgid/django-users/fae01772-7a30-4552-a104-0e5f519733de%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/django-users/313561f4-9d87-4d42-aa86-516cde037ee6%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/313561f4-9d87-4d42-aa86-516cde037ee6%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFwN1upuL%2BjyHam9o%3DqsTDSQpbGDLGgcPNFmebYQj5rvyy2KEw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.