编写聊天应用程序

编程入门 行业动态 更新时间:2024-10-26 14:36:20
本文介绍了编写聊天应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道为成千上万的用户编写聊天应用程序的正确方法是什么。

I'm wondering what's the right way to code a chat application for thousands of users.

我很困惑我怎么能够使用AJAX每秒或更短时间ping服务器并检查MySQL中是否有新记录,服务器负载量是否可接受。

我目前正在考虑使用jQuery,PHP和MySQL进行编码。

I'm currently thinking about coding this using jQuery, PHP and MySQL.

请指教。非常感谢您的帮助。

Please advice. Your help would be greatly appreciated.

推荐答案

客户端

任何需要轮询服务器的程序我都建议 WebSockets 。

我写了极其基本的WebSocket教程。我还使用了web-socket-js代码来实现一个FlashSocket,它可以在Firefox,IE 8+和Chrome以及支持WebSockets的任何浏览器上运行。

I wrote an extremely basic WebSocket tutorial. I also used the web-socket-js code to implement a FlashSocket that will make it work across Firefox, IE 8+, and Chrome, as well as any browser that supports WebSockets.

我不认为民意调查对于聊天应用程序来说是个不错的选择。虽然它可以工作,但是请求开销会比使用WebSocket高得多。权衡(好处)是更多的浏览器支持它。

I don't believe that polling would be a good choice for a chat application. While it would work, the request overhead would be much higher then using a WebSocket. The tradeoff (benefit) is that more browsers support it.

此外,点击MySQL数据库以查看是否有消息将导致大量的数据库开销。我建议使用MySQL数据库进行聊天记录,并且只保留有限数量的后退消息,以便进行新的连接。然后只需向所有连接的客户端广播新消息。然后,前端应用程序将接收消息并将其附加到聊天窗口。

Also, hitting a MySQL database to see if there are messages is going to incur a good deal of DB overhead. I would recommend using a MySQL database for chat logs, and only keep a limited number of "back" messages on hand for new connections. Then simply broadcast new messages to all connected clients. The frontend application would then take the message and append it to chat window.

Node.js是一个公平的服务器端JavaScript框架。虽然它还很年轻,但已经编写了几个非常有趣的应用程序。 Node.js人员设置聊天程序(而不是WebSockets),其来源为已经可用。如果不想从头开始编写,这将是一个非常好的起点。

Node.js is an evented server-side JavaScript framework. While it is still young, several very interesting applications have been coded in it. The Node.js people setup a chat program (not WebSockets) the source of which has been made available. That would be a very good place to start if not wanting to write it from scratch.

有一个 PHP WebSocket 实现。根据您的要求,它可以使用得很好。在Node.js和PHP中编码我会说我认为Node.js更适合这个。

There is a PHP WebSocket implementation. Depending on your requirements it could be used just fine. Having coded in both Node.js and PHP I would say I think Node.js is a better fit for this.

更多推荐

编写聊天应用程序

本文发布于:2023-05-26 10:17:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/252261.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:词库加载错误:Could not find file 'D:\淘小白 高铁采集器win10\Configuration\Dict_Sto

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!