从服务器端应用程序向客户端推送消息? [英] Pushing messages to clients from a server-side application?

查看:251
本文介绍了从服务器端应用程序向客户端推送消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于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.

我的问题是如何通知我的客户有新内容要显示?我对任何额外的技术开放,我必须实现这个解决方案。

推荐答案

轮询是要走的路。您可以使用Flash或Silverlight或Comet - http://en.wikipedia.org/ wiki / Comet_(编程),它可以保持tcp连接为您打开通知。

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.


但是想想,有多少客户端可以同时持有到一个服务器的tcp连接?对于一个更大的系统,你可以快速用尽可用的套接字,因为有65k端口可用。
0007您的服务器可以处理多少并发连接取决于您的硬件资源。如果你有足够的内存和cpu,你应该能够处理〜100k或许更多。但是如果每个请求通过tcp / ip访问数据库或其他资源,您可以限制每个ip可用端口数(65k)。您还应该针对单独的域执行推送请求,因为浏览器通常会覆盖每个域的两个并发连接,因此您不会影响正常的网页加载。

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.

使用轮询与缓存服务器结合使用是一个很好的解决方案。您可以在服务器上拥有每个客户端更新高速缓存的逻辑,从而减少每次轮询的负载。您可以更新已在X分钟内登录/轮询的用户的缓存,以减少缓存更新。对我来说,实施拉力比拉力更容易,技术聪明。

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.

这篇关于从服务器端应用程序向客户端推送消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆