开发者

Developing Chat API like that of Stackoverflow [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this ques开发者_开发技巧tion? Update the question so it focuses on one problem only by editing this post.

Closed 6 years ago.

Improve this question

How to begin developing chat api, like the one stackoverflow uses? If it is open source, where can i find it, if not can anyone guide me how to build a similar chat api?


Now its the time of comet.
comet is reverse ajax.If you are using ajax in chat applications u need to check everytime for database updations but in the case of comet its all about server side events.

We can set the certain events @server side then it will automatically update the webpage when the database is getting updated.that is we do not need to give requests all the time.

So that we can avoid the server headache due to large number of requests and the application will be very much faster.

This is a live chat example using comet.
check it out: http://www.zeitoun.net/articles/comet_and_php/start

its beyond ajax


You can build a very simple PHP chat room with jQuery's AJAX functionality if you don't want to bother with the complexity of COMET. Regardless of what the server side API looks like, you can probably interact with it using jQuery from the client.

Clients can poll the server using jQuery code like this:

$(document).everyTime(pillowchat.settings.message_poll_frequency, function() {
     if(pillowchat.state.poll == true){    
        getMessages();
    }
}); 

jQuery POST requests could be sent like this:

$.post("chat.php", {
    "attribute":"important string"
},
function(data){ 
    response = JSON.parse(data);
    processNewMessages(response);
});

They could be requests for new messages, active users, or contain new messages from the client.

The API on the server can be implemented a million different ways. I wrote a simple chat using PHP and CouchDB that worked pretty well. More detail and source code is available here: http://trillworks.com/nick/2011/08/13/pillowchat-how-not-to-build-a-chat-room-with-jquery-phpillow-and-couchdb/

I wouldn't recommend this approach if your expect more than 30 people in the room. When stress testing this design, I found apache couldn't handle all the traffic. Make sure you include some sort of flood detection.


I does not have much to do with SO chat but this may be a start, it Open Source and really good in my opinion.

AJAX Chat

Hope it helps, good luck!


This chat plugin looks like the facebook one: http://anantgarg.com/2009/05/13/gmail-facebook-style-jquery-chat/ and this is a tutorial http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=335

I hope it helps.


I would highly highly recommend checking out the APE project. It stands for Ajax Push Engine and it uses Comet Server techniques/technology. This project is designed to handle tens of thousands if not hundreds of thousands of users at a time and it provides the server end and the JS interface client. It is compatible with all the major JS libraries.

Its well thought out, clean, and most importantly FREE!

Also I am sure that there are CMS plugins that exist that utilize it. The DrupalChat module has been talking about using it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜