Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've seen many games on FB have queue which connects you to an opponent you should be playing against.

So my question is: In which language can it be coded? Is it possible to do it in PHP/Javascript?

Does anyone have any real/live example or tutorial how is this done?

Thanks in advance!

share|improve this question
add comment

1 Answer

You can write up a system like that in any Turing-complete language. It's really not that complicated. Here's the basic, high-level principle (for one way to do it; you can probably do it other ways):

You have a list of all people waiting for a match. (Not necessarily a List list, but some data structure that can hold multiple people.) When a new applicant shows up, check them against the list and see if you find a suitable match. If so, pull the match off the list and send each player's system a notification that they need to connect with the other system. Otherwise, add the newcomer to the list. If someone gets tired of waiting and disconnects, remove them from the list.

Details of how to implement this will obviously vary quite a bit depending on exactly what your system is doing. In the simplest case, there's no such thing as an unsuitable match, so your waiting list will never be longer than one player. At the other extreme, if your list is likely to contain thousands of players for whatever reason, you might want to look at optimizing the lookup somehow. But in the in-between territory, the technique I just described will probably work well.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.