php mysql jquery javascript chat

好的,我正在开发类似聊天环境的东西,如果不是,我想近乎实时 实时对话。 但我知道浏览器每次只会为每个域的事务放弃2个线程。 因此,我试图找到一种方法来进行同步聊天,而不会真正影响浏览器。 我也知道浏览器倾向于锁定同步请求。</ p>

那么从头开始在网站上创建类似聊天的最佳方法,假设数据库和脚本概念很好,它的 管理连接,想知道如何保持一个持久的连接,不会使浏览器拥塞并导致它可能冻结。</ p>

任何人有任何想法..我不是在寻找闪存 或基于java的解决方案。 我也不想每秒都进行一次民意调查。 但什么是叠印,你会做什么。</ p>
</ div>

展开原文

原文

Ok, I am working up something like a chat environment, and I'd like to have near real time if not real time conversation. But I know browsers will only give up 2 threads at a time for transactions per domain. So I am trying to figure out a way to make a synchronous chat without really effecting the browser. I also know browsers tend to lock up with synchronous requests.

So whats the best approach at creating a chat like environment on a site from scratch, assume the DB and scripting concept is fine, its the managing of the connection, wondering how to keep a persistant connection that won't congest the browser and cause it to possibly freeze up.

Anyone have any ideas.. Im not looking for flash, or java based solutions. I'd prefer not to poll every second either. But what is stacks impression, what would you do.

dongtao4787
dongtao4787 同步聊天而不影响浏览器?同步的定义使得这是不可能的。无论如何,请查看Web套接字,特别是Socket.IO。
8 年多之前 回复

2个回答



首先,规范只建议允许两个连接。 大多数现代浏览器实际上最多支持6个。</ p>

使用纯Javascript创建聊天系统有三种主要接受的方法:</ p>

轮询</ strong> </ p>

第一个解决方案很简单,只需每隔几秒轮询一次服务器(5是一个很好的数字),看看错过了什么。 它工作简单有效,但如果不小心可能会导致大量不必要的请求,这可能会导致不必要的服务器负载。</ p>

更好的实现方法是轮询以简单检查是否发生了任何事情 自上次聊天更新以来,如果是这样,只有这样才能查看发生了什么。 节省服务器负载和带宽前端。</ p>

等待</ strong> </ p>

此方法更常用,涉及浏览器发送 对服务器的请求永远不会被满足,而是保持“等待响应”。 当某些事情发生时,服务器输出它并完成请求,并且客户端发出另一个请求并重复该过程。 这样可以节省请求,但最终可能会在服务器上积压正在进行的进程。</ p>

Websockets </ strong> </ p>

https://developer.mozilla.org/en/WebSockets </ p>
\ n

这涉及创建与服务器的直接套接字连接,允许在需要时将数据推送到客户端。 虽然它相对较新,并且可能存在一些兼容性问题,特别是对于旧版浏览器。</ p>

其中,没有一个是特别的“最佳方法”; 这取决于你的目标是什么,重要的是什么。 如果你有一个专为最新浏览器设计的网站,那么websockets可能就是你的答案,但如果你有一个小型服务器,那么轮询可能会更好,例如。</ p>
</ DIV>

展开原文

原文

First off, the spec only suggests that two connections are allowed. Most modern browsers actually support up to 6.

There're three main accepted methods for creating a chat system out of pure Javascript:

Polling

The first solution is simple, and just involves polling the server every few seconds (5 is a nice number) to see what it's missed. It works simply and efficiently, but can lead to large amounts of unnecessary requests if not careful, which can cause unnecessary server load.

A better implementation of this involves polling to simply check if anything's happened since the last chat update, and if so, only then go through the process of finding out what's happened. Saves on the server load and bandwidth fronts.

Waiting

This method's more commonly used, and involves the browser sending a request to the server which is never fulfilled, and instead keeps 'waiting for a response'. When something happens, the server outputs it and fulfills the request, and the client makes another request and the process repeats. This saves on the request front, but can end up with a backlog of ongoing processes on your server.

Websockets

https://developer.mozilla.org/en/WebSockets

This involves creating a direct socket connection to the server, allowing data to be pushed to the client when needed. It's relatively new though, and can have some compatability issues, especially with older browsers.

Out of these, none of them is specifically the 'best method'; it depends on what you're aiming for, and what matters. If you've got a site designed for up-to-date browsers, then websockets could be your answer, but if you've got a small-ish server, then polling could be better, for example.

dppfxf909679
dppfxf909679 总的来说,虽然这个特别的事情是创建一个移动聊天,它将在它启动时运行超过4个小时,但是每个房间将有多个房间可容纳几百人(或者希望如此 )
8 年多之前 回复
dongxian6285
dongxian6285 所有案件的好论据。 看到这样的3个方面总体上得出了更好的结论,然后开始进行更多的研究。 我很感激。 总的来说,我会说我们的网站将更适合现代浏览器,我们打算支持旧浏览器到一个点,但希望是大多数将来现代化。 这通常也是临时解决方案。 最终我们可能会有双重概念。 一个可以使用套接字作为主要服务器,另一个可以用于轮询或等待作为回退。
8 年多之前 回复



我自己的聊天引擎每五秒检查一次新消息。 这很接近于没有人知道差异。</ p>

它就像 setInterval(updateChat,5000); </ code>。</ p>
</ div一样简单 >

展开原文

原文

My own chat engine checks for new messages every five seconds. That's close enough to instant that nobody knows the difference.

It's as simple as setInterval(updateChat,5000);.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐