0

I am doing random chat like http://www.omegle.com/ for fun. Here how it goes:

Person logins, his id is inserted in seaching_chat table. He presses "Search" button and if there any other people in searching_chat, we connect them and delete information from seaching_chat table. If there are no people in the table, we use javascript and every 10 seconds check the mysql database to find out if somebody loged in.

So, is it the most efficient way to do such a thing? Any advices, ideas?

3 Answers 3

2

WebSockets and nodejs are insanely difficult and too comprehensive for something easy like this. A long pull is indeed a good idea (the simplest and best imo). A simple, closing request every 2 or 5 seconds doesn't cost anything either, because there's always only 1 person waiting/firing those requests. 2 people -> connect. 3 people -> 2 ppl connected and 1 waiting. etc

Sign up to request clarification or add additional context in comments.

Comments

1

That sounds like a reasonable solution, but to not make matched users wait up to 10 seconds before they are connected with another user you may want to look at doing a "long pull" where the ajax connection to your server-side login check script is held open until another user logs in... then your server script finally responds with the proper payload to let the user's javascript know to redirect to the chat room.

You could also do this with WebSockets, which would probably be a great tech to base the chat room on if you want it to be highly responsive... but browser support is a bit weak right now.

Comments

0

Yes, I think WebSockets is the way to go with this. Take a look at node.js and socket.io. Socket.io provides a nice way to do WebSockets and even supports older browsers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.