One trick i used uas to send values in comment to get long pooling with disconnect check
Like for json:
Send 0 and flush before connection aborted.
Eg. {"x":"000000
And after result is ready send ", and json after removing 1st {
So it looks like
{"x":"00000000000","y":"result","z":"result2"}