Server-push Technology (Comet)----------asp.net asynchronous processing +client long connection to the server side

Source: Internet
Author: User
Keywords Server-side HTTP long connection Nbsp; dler
Tags .net ajax apply asp asp.net available for block client

Server-push technology has been available for a long time, but until the birth of gtalk slowly guide the technology, but so far, very few people to apply this technology, Server-push is a what kind of things?

Hence the name of righteousness, Server-push is the meaning of "server Push", Ajax have been used, it and Server-push is the opposite two things, Ajax is pulled from the server side of the data, if you want to regularly update the data block displayed on the page, the easiest way is to write a timer, Server-push is different, it is the essence of the client and server to establish a long connection, that is, after the continuous open, once the server has new data to push it to the client, said there are several problems here.

What is the difference between 1.ajax and Server-push and the same point?

A: What Ajax has in common with Server-push is that they also use JavaScript to implement data without a refresh, except that if you use AJAX to update your data at all times, you will periodically fetch the data to the server regardless of the server-side data. This causes some unnecessary consumption, the server caused a certain amount of pressure, and Server-push is different, it is in the server to generate new data when the client data feedback, but the disadvantage is also due to this, because it will occupy the number of connections to the Web server, A Web server with a large user access and a certain limit on the number of connections does not apply to Server-push.

2. How do I find new data on the server side?

A: This problem needs to be based on the specific application environment, if the "Instant Messaging" tool for online user statistics, server-side found that there is a new user login, that is, to all clients to push data, there is a more use of multithreading on the server side to monitor data changes.

3. How does the server side push data to the client?

A: This issue is the most critical, the server side how to push data to the client?. NET has an asynchronous callback that enables server-side push to client data, and what about asynchronous callbacks in. Net? It's really simple.

e.g. write a class that, if used specifically to implement asynchronous callbacks, must be aware of the following points

1> inherits IHttpAsyncHandler interface//defines the contract that the HTTP asynchronous handler object must implement.

2> The following methods can not be less

Initiates an asynchronous call to an HTTP handler. Public IAsyncResult BeginProcessRequest (HttpContext context, AsyncCallback cb, Object Extradata) {}//The asynchronous processing end method is provided when the process ends. public void EndProcessRequest (IAsyncResult result) {}//Gets a value that indicates whether the IHttpHandler instance can be used by other requests. (inherited from IHttpHandler.) public bool Isreusable{get {return false;;}///enable processing of HTTP WEB requests by implementing the custom HttpHandler of the IHttpHandler interface. (inherited from IHttpHandler.)   public void ProcessRequest (HttpContext context) {throw new NotImplementedException ();}//Focus here, here is responsible for writing data to client try { Context. Response.Write (This.value); if (m_callback!= null) {m_callback (this);//This is done, the client Ajax request can get to the server-side pushed data} catch {} finally {m_iscompleted = true;}

This in the above method refers to another class that inherits the interface IAsyncResult (//) representing the state of the asynchronous operation.

In the end, Server-push requires a long connection between the client and the server, and this long connection cannot be broken, so that once something is uploaded to the client by the server, the push of the data requires the use of the. NET asynchronous callback. There is no specific code written here, and it may seem a bit hard for a friend who has not touched the. NET asynchronous callback, but first understand the rationale and then slowly explore the technology.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.