Java Servlet 3.0 server push: Sending data multiple times using same AsyncContext

拜拜、爱过 提交于 2019-11-30 10:34:21

Your server-side and client-side code is indeed ok. The problem is actually with your browser buffering text/plain responses from your web-server. This is the reason you dont see this issue when you use curl.

I took your client-side code and I was able to see incremental responses, with only just one little change:

response.setContentType("text/html");

The incremental responses showed up immediately regardless of their size.

Without that setting, when my output was a small message, it was considered as text/plain and wasnt showing up at the client immediately. When I kept adding more and more to the client responses, it got accumulated until the buffer size reached about 1024 bytes and then the whole thing showed up on the client side. After that point, however, the small increments showed up immediately (no more accumulation).

I know this is a bit old, but you can just flushBuffer on the response as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!