ASP.net如何长轮询与PokeIn? [英] ASP.net how to long polling with PokeIn?

查看:139
本文介绍了ASP.net如何长轮询与PokeIn?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要作出这样的通知的情况下有发送给他一些新的消息的用户的服务。因此,我想用一些彗星的框架,提供服务器推送能力。所以我看着 PokeIn

I want to make a service that notify the user in case there are some new messages sent to him. Thus I want to use some Comet framework that provide the server push ability. So I have looked into PokeIn.

只是想知道的事情。我已经检查了,他们有网站上的样品。他们没有寻找到数据库中,如果有一些检索新的条目。但是,它仅仅是一个修改的事吧,我猜。

Just wondering a thing. I have checked on the samples that they have on the website. None of them look into the database to retrieve new entries if there are some. But it is just a matter of modification to it I guess.

其中的样品通过使用在服务器侧的睡眠实现此长轮询。所以,如果我用同样的方法,我可以检查数据库,如果有任何新条目,每5秒。然而,这种做法似乎并没有要上使用JavaScript客户端使用轮询时,从很大的不同。

One of the sample implement this long polling by using a sleep on the server side. So if I use the same approach I can check the database, if there are any new entries, every 5 seconds. However this approach doesn't seem to be much different from when using polling on the client side with javascript.

这部分是从样品。可以看出,他们把睡眠那里来更新当前时间为大家。

This part is from a sample. As can be seen they put a sleep there for to update current time for everybody.

static void UpdateClients()
    {
        while (true)
        {
            //.. code to check database 
            if (CometWorker.ActiveClientCount > 0)
            {
                CometWorker.SendToAll(JSON.Method("UpdateTime", DateTime.Now));
            }
            Thread.Sleep(500);
        }
    }

所以我想这是我应该怎么实现消息通知?看来,上述做法仍在继续推动在服务器端巨大的负载需求。该消息通知是打算工作同样的方式发现之一的Facebook。

So I wonder is this how I should implement the message notifier? It seems that the above approach is still going to push a huge load demand on the server side. The message notifier is intend to work same way as the one found Facebook.

推荐答案

您不应该实行这种方式,样本,才会实现这样因为保持PokeIn相关的部分是明确的。您应该执行SQL语句组成部分所提到的http://www.$c$cproject.com/Articles/12335/Using-SqlDependency-for-data-change-events
为了跟踪数据库更改。

You shouldn't implement this way, that sample is only implemented like that because the keep PokeIn related part is clear. You should implement SQL part as mentioned http://www.codeproject.com/Articles/12335/Using-SqlDependency-for-data-change-events in order to track changes on database.

所以,当你有东西送,打电话的PokeIn方法为客户端传递之一。我不知道,你的应用程序有多少时间是至关重要的,因为除了反向AJAX,PokeIn的内部的WebSocket 功能是很容易激活,并将消息传递到客户端的速度相当快。

So, when you have something to send, call one of the PokeIn methods for the client side delivery. I don't know, how much your application is time critical because in addition to reverse ajax, PokeIn's internal websocket feature is very easy to activate and delivers messages to client quite fast.

这篇关于ASP.net如何长轮询与PokeIn?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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