开发像 Stackoverflow 一样的聊天 API

发布于 2024-10-05 17:01:46 字数 1436 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

手心的温暖 2024-10-12 17:02:26

我强烈建议您查看 APE 项目。它代表 Ajax Push Engine,它使用 Comet Server 技术/技术。该项目旨在一次处理数万甚至数十万用户,它提供了服务器端和 JS 接口客户端。它与所有主要的 JS 库兼容。

它经过深思熟虑,干净,最重要的是免费!

我也确信存在利用它的 CMS 插件。 DrupalChat 模块 一直在讨论如何使用它。

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.

不顾 2024-10-12 17:02:21

这个聊天插件看起来像 facebook 插件: http://anantgarg .com/2009/05/13/gmail-facebook-style-jquery-chat/ 这是一个教程 http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=335

我希望它有帮助。

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.

秋日私语 2024-10-12 17:02:17

我与 SO 聊天没有太多关系,但这可能是一个开始,它是开源的,在我看来非常好。

AJAX 聊天

希望它有帮助,祝你好运!

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!

凯凯我们等你回来 2024-10-12 17:02:09

如果您不想担心 COMET 的复杂性,您可以使用 jQuery 的 AJAX 功能构建一个非常简单的 PHP 聊天室。无论服务器端 API 是什么样子,您都可以在客户端使用 jQuery 与其进行交互。

客户端可以使用 jQuery 代码轮询服务器,如下所示:

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

jQuery POST 请求可以这样发送:

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

它们可以是对新消息、活动用户的请求,或包含来自客户端的新消息。

服务器上的 API 可以通过一百万种不同的方式实现。我使用 PHP 和 CouchDB 编写了一个简单的聊天,效果非常好。更多详细信息和源代码可在此处找到:http://trillworks.com/nick/2011/08/13/pillowchat-how-not-to-build-a-chat-room-with-jquery- phpillow-and-couchdb/

如果您预计房间里有超过 30 人,我不会推荐这种方法。当对这个设计进行压力测试时,我发现 apache 无法处理所有的流量。确保包含某种洪水检测。

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.

傲影 2024-10-12 17:02:02

现在是彗星的时间。
comet 是反向 ajax。如果您在聊天应用程序中使用 ajax,则需要每次检查数据库更新,但对于 comet 来说,它全部与服务器端事件有关。

我们可以在@server端设置某些事件,然后当数据库更新时它会自动更新网页。也就是说我们不需要一直发出请求。

这样我们就可以避免由于大量请求而导致服务器头痛,并且应用程序会更快。

这是使用 comet 的实时聊天示例。
看看:http://www.zeitoun.net/articles/comet_and_php/start

它超越了ajax

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文