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>