从服务器端应用程序向客户端推送消息?

发布于 2024-09-13 02:08:14 字数 174 浏览 3 评论 0原文

我有一个基于 javascript 的客户端,当前正在轮询 .NET Web 服务以获取新内容。虽然轮询有效...我对这种方法不满意,因为我正在使用系统资源并在没有接收任何更改时产生开销。

我的问题是如何通知我的客户有新内容可供显示?我对实施此解决方案所需的任何其他技术持开放态度。

I have a javascript-based client that is currently polling a .NET web service for new content. While polling works...I'm not happy with this approach because I'm using system resources and creating overhead when there aren't any changes to receive.

My question is how do I notify my client(s) that there is new content for it to display? I am open to on any additional technologies I would have to implement this solution with.

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

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

发布评论

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

评论(5

捂风挽笑 2024-09-20 02:08:14

首先,民意调查是可行的方法。您可以使用 Flash 或 Silverlight 或 Comet - http://en.wikipedia.org/ wiki/Comet_(programming) 它可以为您打开 TCP 连接以获取通知。 网页本身无法保持套接字打开,因此无法直接通知 Web 客户端。

[编辑]
但是想一想,一次可以有多少个客户端与一台服务器保持 tcp 连接?对于较大的系统,您很快就会用完可用的套接字,因为有 65k 个可用端口。

您的服务器可以处理多少并发连接取决于您的硬件资源。如果你有足够的内存和CPU,你应该能够处理~100k甚至更多。但是,如果每个请求都通过 tcp/ip 访问数据库或某些其他资源,则可能会限制每个 ip 可用的端口数 (65k)。您还应该让推送请求针对单独的域,因为浏览器通常限制每个域有两个并发连接,这样就不会干扰正常的页面加载。

使用轮询结合前面的缓存服务器是一个很好的解决方案。您可以在服务器上使用逻辑来更新每个客户端的缓存,从而减少每次轮询的负载。您可以为在 X 分钟内登录/轮询的用户更新缓存,以进一步减少缓存更新。对我来说,从技术角度来看,实施拉动比拉动更容易。

First of all, polling is the way to go. You could do it with Flash or Silverlight or Comet - http://en.wikipedia.org/wiki/Comet_(programming) which can hold a tcp connection open for you for notifications. A webpage itself cannot hold a socket open, so there is no way to directly notify a web client.

[Edit]
But think about it, how many client can hold a tcp connection towards one server at a time? For a larger system you would run out of available sockets pretty fast as there are 65k ports available.

How many concurrent connections your server can handle depends on your hardware resources. If you have enough memory and cpu you should be able to handle ~100k and maybe more. But if each request access a database or some other resource over tcp/ip, you could be limited to the number of ports per ip available (65k). You should also have the push requests go against a separate domain, as a browser normally caps to two concurrent connections per domain, so you won't interfere with the normal page loading.

Using polling in combination with cache servers in the front is a good solution. You can have logic on the server which updates the cache per client, reducing the load for each poll. You could update the cache for users who have signed in/polled within the X number of minutes to reduce the cache updating even more. And to me implementing pull is easier than pull, technology wise.

﹏雨一样淡蓝的深情 2024-09-20 02:08:14

您应该研究COMET

<块引用>

COMET 是一种使服务器能够通过 HTTP 开放通信线路将数据推送到客户端浏览器的技术。

那里可能有关于 COMET + WCF Web 服务的示例。

You should research about COMET.

COMET is a Technique that enable a server to push data to client browsers through an HTTP open line of communication.

Probably there are examples overthere about COMET + WCF Web services.

节枝 2024-09-20 02:08:14

查看 WebSync,这是一个针对 .NET/IIS 的 Comet 解决方案。它会完全满足您的需求。没有额外的轮询浪费资源,只在需要时推送,实时更新......整个9码。

Check out WebSync, a comet solution for .NET/IIS. It'll do exactly what you're looking for. No extra polling wasting resources, push only when needed, real-time updates...the whole 9 yards.

友欢 2024-09-20 02:08:14

http://www.ape-project.org/ 我认为这是一个不错的地方看。它基于 ajax 推送,或者有些人称之为反向 ajax。还有其他项目,它基于: http://en.wikipedia.org /wiki/Comet_(programming)

我提到了 ape 项目,因为你可以使用 JavaScript,或者如果你想在服务器端使用 C++、PHP、Python 等。 :-)

http://www.ape-project.org/ is I think a good place for you to look. Its based on ajax push or as some call it reverse ajax. There are other projects as well and it is based on: http://en.wikipedia.org/wiki/Comet_(programming)

I mentioned ape project because you can use JavaScript with it or if you want C++, PHP, Python, etc on the server side. :-)

屌丝范 2024-09-20 02:08:14

您已经了解过 HTTP 轮询 (COMET)。这就留下了一个问题:http 服务器本身(IIS+ASP)如何在不轮询数据库的情况下检测数据库中的更改。对于 SQL Server,您可以使用诸如查询通知之类的技术,该技术允许您的 ASP.Net 进程在数据库中缓存的记录发生更改时收到通知。您还可以查看 LinqToCache 项目,该项目允许将查询通知与 LINQ 查询混合。

You've been already told about HTTP polling (COMET). This leaves open the question how does the http server itself (IIS+ASP) detect the changes in the database without polling the database. With SQL Server you can use a technology like Query Notifications, which allows your ASP.Net process to be notified when a change occurs in the database on a record it has cached. You can also check out the LinqToCache project that allows Query Notification to be mixed with LINQ queries.

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