Http://www.cnblogs.com/zengqinglei/archive/2013/03/31/2991189.html
Comet is also called reverse Ajax or server-side push technology. The idea is simple: push data directly from the server to the browser without waiting for the browser to request data.
Main idea: server-side push data to client (browser)
I made a simple Web Live chat system: Server push (chat). zip
The system is briefly described as follows:
{
Database used by the system: SQLite database
UserInfo: User Information table
Userrelation: User Relations table
Messageinfo: Chat Information table
Development structure:
Structure diagram:
Three-tier development:
Data Layer--interaction with SQLite database
Logic Layer--data conversion
Entity Layer--data object
Web services: The use of webservice to provide a common interface, mainly to provide client and server-side data interaction.
Client (ASP): Push chat messages with Ajax reverse technology in comet.
Project Operation Demo Effect:
1. User Login (test account {liger_zql,12345},{indifferent, 12345})
Description: Open two tabs with your browser to browse the Login.aspx page as follows
2. Chat interface
After successful login, the two tabs jump to the following interface: Double-click the line in the online friend to start the chat.
LIGER_ZQL Chat Interface:
Indifferent Chat Interface:
The chat process is using comet push technology.
3. User Registration Interface
}
Comet push technology in the project
Client
Ajax Long Polling
function Postsubmit (params, success) { $.post ("Comet_broadcast.asyn", params, success, "JSON");} function Keepline () { var array = new Phparray ("Keepline"); var success = function (data, status) { if (data). ResponseStatus = = 1) { showmessage (data. ResponseData, "recive"); } Keepline (); } Postsubmit (Array. ToJson (), success);}
Server-side:
#region Send message private void sendmsg () { Messageinfo message = new Messageinfo () { Senduserid = m_ context.request["UserId"], Reciveuserid = m_context.request["Reciveuserid"], Content = m_context.request[" Content "] }; Gets the server-side processing results of string result = SDK. SEND_MSG (message); if (Dict. ContainsKey (message. Reciveuserid)) { //To send information to dict[message. Reciveuserid]. result = result; Dict[message. Reciveuserid]. Send (); } Send the processing result to yourself _iasyncresult.result = result; _iasyncresult.send (); } #endregion
Where (Project site--webchat_serverpush and server-side processing--serverpushhttphandler) requires the following configuration in the Web. config configuration file:
Comet is a Web application model in which requests are sent to the server side and maintain a long lifetime until a timeout or server-side event occurs. After the request is complete, another long-lived Ajax request is sent to wait for another server-side event. With comet, the Web server can send data to the client without explicit requests.
One of the great advantages of comet is that each client always has a communication link open to the server side. The server side can push events to the client by committing (completing) the response as soon as the event arrives, or it can even accumulate and then continue sending. Because requests remain open for long periods of time, the server side needs special features to handle all these long-lived requests.
Source: Server Push (chat). zip
Finally I wish there is a need to understand the technology of the program APE Day!!! (~ o ~) ~zz
Zengqingrei Source: Http://www.cnblogs.com/zengqinglei This page copyright belongs to the author and the blog Park all, welcome reprint, but without the author's consent must retain this paragraph statement, and in the article page obvious location give the original link, otherwise reserve the right to hold legal responsibility
Tags: Web live chat Comet Server Push Technology AJAX reverse technologyBased on Comet server Push technology (Web live chat)