Long polling in java

故事扮演 提交于 2019-12-04 15:24:11

The call to HTTPURLConnection's getInputStream gives back a blocking stream. Calling a read on this stream will block the thread till data is available from the server, you need not keep polling for data.

Call the read in a separate thread and keep the HTTPURLConnection in scope without closing the connection. This should get you back the data nwhen available. Once you receive a 200OK from the server, send back another request on the same connection to keep it open. (This is if you have not implemented a request timeout.)

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