E
E
Empty User2014-09-14 20:01:33
Algorithms
Empty User, 2014-09-14 20:01:33

How to make a random chat?

I am making a random chat where the user communicates with a random interlocutor. So, in principle, everything is ready, but I'm not sure if I'm doing it right ...
There is an array, rooms are stored there, and there is only one room or nothing. And so actually how it all works:
The user presses the "Find" button. The server checks the array:
-If the array is empty, it creates a new room and adds the room ID to the array. We display the message "Wait ..." for the user.
-If there is already an element in the array, then we connect to the room, remove this room from the array. Communication begins.

Am I doing the right thing? If not, please suggest your choice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Zakharov, 2014-09-14
@dimash07

There is an array, rooms are stored there, and there is only one room or nothing.

Then why take an array? If there is only one element. Let there be one object that is either null or not null.
In general, you need to look at the details of the task and the architecture of the application (server) - if the server can be heavily loaded, then it is better to use some other data structure. Thread-safe queue, for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question