Asp.net use Comet to develop http persistent connection examples

Source: Internet
Author: User

Comet (Reverse AJAX) is mainly used to maintain a connection with the Server through HTTP persistent connections to implement Server PUSH and bidirectional communication. The following uses an example to learn how to use it.

Benefits: 1. Resource Saving and low latency compared with AJAX polling. 2. Compared with webSocket, it is widely used. 1. first, create an empty Asp.net MVC project to add a Controller (the same code can also be used in Asp.net WebForm). The Code is as follows: public class CometController: Controller {public ActionResult Test () {Response. buffer = false; while (true) {Response. write (DateTime. now. toString ("yyyy-MM-dd HH: mm: ss FFF") + "|"); Thread. sleep (500) ;}// return Content ("") ;}} 2. create a Controller and View to display the following HTML code: public class HomeController: Controller {// GET:/Home/p Ublic ActionResult Index () {return View () ;}} important code of the View code is as follows: @ {Layout = null ;}<! DOCTYPE html>

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.