开发者

comet example. I don't get it

protected void Page_Load(object sende开发者_高级运维r, EventArgs e)
{
    Response.Buffer = false;

    while (true)
    {
        Response.Write(Delimiter + DateTime.Now.ToString("HH:mm:ss.FFF"));
        Response.Flush();

        // Suspend the thread for 1/2 a second
        System.Threading.Thread.Sleep(500);
    }

    // Yes I know we'll never get here, it's just hard not to include it!
    Response.End();
}

When Response.Flush() is executed, the new webpage is sent to the client The while block will run forever on the server When the new maeeage reaches the client, there is a refresh for the new data How is it posible to continue the same place. Shouldn't there be a new Page object created?


There are a few problems with what you've described...

1) You've described mis-matching client and server code. The server code there only works with a single AJAX request that hangs around forever, and gets notified on the client but doesn't start a new request. In your comments, however, you've described a client that does start a new request. Those 2 concepts won't work together.

2) Elaborating on point 1, the request never ending means that most browsers will never see it. "Typical" AJAX requests won't change state until the entire contents arrive, so that request will just hang forever. You'll have to end the request, or use an XHR request that changes state as each chunk is flushed from the server, which only would be viable in certain browsers.

3) Even if 1) worked, proxies, etc, would kill the request eventually. They don't like requests sitting around forever.

4) That's a blocking synchronous request, which'll eat server resources like crazy. That won't get beyond a the threadpool limit before it fails catastrophically.

So yea, the example you've given here doesn't make sense :).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜