Reputation: 594
I have banged my head loads of time but couldn't find any good commet example. Me and my friend are developing a small chat software in PHP, I need the commet thing urgently please guys if anybody can explain that in simple words. I will be grateful. Thank you
Upvotes: 0
Views: 523
Reputation: 331
Commet is just another way of long polling. Essentially, you use something like jquery to make a call to the server. The server keeps that call open until it either:
When the server returns, your jquery do something with any data that might have been returned and then kick off another call to the server.
An example of the javascript function is as follows:
function commetpoll() {
$.get("/myserversidescript.php", {}, function(data) {
//Do something with data
commetpoll();
}));
};
Upvotes: 0
Reputation: 5279
There are couple of ways in which you can implement :
In case of repeated polling
you client keeps polling the server after a certain interval to check if there is a new message.
In case of server push
you client maintains and active connection to the server via socket or something similar and then the server notifies the client via a push
In case of long polling
the client makes a request the server doesn't respond immediately but waits until there is some message to be sent. So either after som time the client receives the message or the client times out and starts a new request.
Upvotes: 1