How to pair users? (Like Omegle.com)

Posted by Carlos Dubus on Stack Overflow See other posts from Stack Overflow or by Carlos Dubus
Published on 2010-05-05T02:47:53Z Indexed on 2010/05/05 2:58 UTC
Read the original article Hit count: 255

Filed under:
|
|
|

Hi, I'm trying to do an Omegle.com clone script, basically for learning purposes. I'm doing it in PHP/MySQL/AJAX.

I'm having problems finding two users and connecting them. The purpose of omegle is connecting two users "randomly".

What I'm doing right now is the following:

  • When a user enters the website a session is assigned.
  • There are 3 states for each session/user (Normal,Waiting,Chatting)
  • At first the user has state Normal and a field "connected_to" = NULL
  • If the users clicks the START button, a state of "Waiting" is assigned. Then it looks for another user with state Waiting, if doesn't find one then it keeps looping, waiting for the "connected_to" to change. The "connected_to" will change when other user click START and then find another user waiting and updates the sessions accordingly.

Now this have several problems, like:

  • A user only can be connected to one user at a time. In omegle you can open more than one chat simultaneously.
  • I don't know if this is the best way.

About the chat, each user is polling the events from the server with AJAX calls, I saw that omegle, instead of several HTTP requests each second (let's say), does ONE request and wait for an answer, that means that the PHP script is looping indefinitely until gets an answer.I did this using set_time_limit(30) each time the loop is started. Then when the Ajax call is done start over again. Is this approach correct?

I will appreciate a LOT your answers, Thank you,

Carlos

© Stack Overflow or respective owner

Related posts about AJAX

Related posts about chat