Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Comet need chunked-encoding response?

I read some articles about Comet tech. All of them mentioned that the long-life HTTP response should be Transfer-Encoding: chunked . I'm wondering why it should be chunked-encoded. If the response is not chunked-encoded, the client javascript can still read and parse the responded text, right?

Is there any special reason that Comet response should be chunked-encoded?

like image 689
Morgan Cheng Avatar asked Nov 18 '25 00:11

Morgan Cheng


1 Answers

Chunked-encoded response is used when the length of the response is not known until the response is completed. An empty chunk indicates the end of the response. This is the only way the client can be notified for the end of response.

All this fit nicely with Comet. You send the first chunk when the request is received. You may also send additional "heartbeat" chunks while waiting for an action to complete. An empty chunk will notify the client that the response is completed.

like image 102
kgiannakakis Avatar answered Nov 19 '25 13:11

kgiannakakis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!