Pushlet、长轮询或轮询 - 我应该在聊天应用程序中使用哪一种?
我必须开发一个多用户聊天应用程序(如msn)。我不知道如何使用任何框架来构建它,因为我想了解这些东西是如何工作的。
我正在用 Delphi 或 C# 开发它,但这并不重要。重要的是聊天客户端将是一个应用程序,而不是浏览器。
问题是:处理客户端之间的消息的最佳方式是什么?
到目前为止,我知道这些技术:
小册子
投票
长轮询
I have to develop a multiple users chat application (like msn). I don't what to use any framework to build it because I want to learn how those things work.
I am developing it in Delphi or C# but it does not really matter. What matter is that the chat client is going to be an app, not a browser.
The question is: what is the best way of handling messages between the clients?
So far, I know those techniques:
Pushlet
Polling
Long polling
Link to the Wikipedia
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来所有这些对于 HTTP 特别有用,因为 HTTP 并不真正允许永久打开连接。如果您正在编写一个使用 Ajax(或 REST 调用)的基于 Web 的聊天客户端,则可以采用这种方法。
如果您自己编写聊天应用程序(P2P 或客户端/服务器),则可以创建永久保持打开状态的连接。
因此,服务器仅侦听给定端口。客户端尝试连接到服务器 IP 地址上的该端口。如果连接成功,它将保持打开状态,直到客户端用户关闭程序(如果一切顺利)。
Delphi 确实有一个使用 Indy TCP 组件的聊天应用程序演示。即使您之后要自己构建它,您也可以先睹为快。
It looks like all of these are particulary useful for HTTP, since HTTP doesn't really allow connections to be permanently open. This is the way to go if you're writing a web based chat client that use Ajax (or REST calls anyway).
If you're writing a chat application (either P2P or client/server) yourself, you can create a connection that stays open permanently.
So, the server just listens on a given port. The client tries to connect to that port on the server's IP address. If the connection succeeds, it stays open until the client user closes the program (if all goes well).
Delphi does have a chat application demo that uses the Indy TCP components. You can take a sneak peak there, even if you're going to build it yourself afterwards.
您需要支持(数万)万个同时连接吗?如果是,我建议查看
,用于应用程序服务器和 Servlet 3.0 等标准,以最大限度地减少工作线程数量并加快网络速度操作
Delphi 有一个 IOCP 库 - 请参阅 是否有一个 I /O Delphi 的基于完成端口的组件?
另外,HTTP 可以用作内部协议,新的 Microsoft http.sys 库提供了良好的基础,并且包含在新版本的 Windows 中。
为了给人一种消息传递服务器的效率有多高的印象:在相对普通的硬件上,开源 ActiveMQ Apollo 服务器每秒可以处理 120 万条消息。 (它是用Java编写的)
Do you need to support (tens of) thousands of simultanous connections? If yes, I recommend to take a look at
which are used in application servers and standards like Servlet 3.0 to minimize the number of worker threads and speed up network operation
There is a IOCP library for Delphi - see Is there a I/O completion port based component for Delphi?
Also HTTP could be used as the internal protocol, the new Microsoft http.sys library provides a great foundation and is included with new versions of Windows.
To give an impression how efficient messaging servers can be: on relatively modest hardware, the open source ActiveMQ Apollo server can handle 1.2 million messages per second. (It is written in Java)