I have some information about Comet, but I want to know how it keeps a connection open (from client to server).
how does it do that?
I have some information about Comet, but I want to know how it keeps
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Comet, or long-polling ajax, doesn’t keep a connection open in the long run.
HTTP is stateless, it sends a request and gets the response. That’s it.
So, how does it look like the connection remains open? Because it’s abusing an HTTP request.
When you send the request, the client waits for the response until it’s coming, or until the server decides that this connection has reached its timeout.
In Comet, the server purposedly doesn’t answer immediately. It only answers when he wants to send a response. This is why the client sends HTTP requests and waits for either a response or the timeout.
This way, it looks like some kind of push from server to client, when it’s just abusing the timeout property of the HTTP requests.
For example, this is some comet code (with jQuery for the sake of keeping it short):