显示键入时键入的字符(即时)
在 Google Wave 的介绍视频中,他们讨论了网络应用程序中的聊天问题。在许多 Web 应用程序中,您会看到类似以下的消息:
Google 提出了一个想法“显示输入时输入的每个字符”以避免出现这种烦人的消息。
你如何创造这样的东西?
In the introduction video of Google Wave they talk about a problem with chat in webapplications. In many webapplications you see a message like: <name> is typing..
(before the message is submitted)
Google came up with an idea "to show each character typed while typing" to avoid this annoying message.
How do you create something like that??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正在编写一个解决方案,我将使用 PHP 套接字并使用更适合这种情况的 UDP 协议。 UDP 协议不可靠,但比最常用于通信的 TCP 快得多。所以我想我会有一个非常轻量级的 PHP 脚本,它会使用 UDP 向处理服务器发送几个字节的数据。使用 AJAX 将数据发送到 PHP 脚本。当然会有延迟,但 UDP 会显着加快交易速度。
If I were writing a solution, I would use PHP sockets and use the UDP protocol which is more fitting for this scenario. UDP protocol is unreliable but much much faster than TCP which is most commonly used for communication. So I guess I would have a very lightweight PHP script that would send a couple bytes of data to a processing server using UDP. Use AJAX to send data to the PHP script. There will be of course delay, but UDP will speed up the transaction significantly.
您可以在浏览器和服务器之间使用某种形式的双向通信。因此,浏览器会将输入的每个字符与服务器进行通信,并且服务器会将该事件发送到所有其他浏览器。这可以通过各种技术来完成,这些技术大多被称为 HTML5 中的 Comet 或反向 Ajax它可以通过 WebSocket 完成。以下是 Comet 服务器实现的列表。
You could use some form of bidirectional communication between the browser and the server. So the browser would communicate to the server every charcter that has been typed and the server would send that event to all the other browsers. This can be done through various techniques mostly known as Comet or reverse Ajax, in HTML5 it can be done via WebSockets. Here is a list of Comet server implementations.