What is the best way to automatically reestablish long polling request?

半城伤御伤魂 提交于 2019-12-14 03:18:43

问题


I am working on a project using long polling, as the nginx server will response 504 Gateway Timeout after the connection established 1 minute or so, I write the error handling function in the $.ajax so that it can automatically reconnect to the server when it receives 504 error. But although I have done this, I don't know whether this is the best practice of long polling mechanism, and this will produce a lot of 504 in log. It seems not good enough, so how should I do it?


回答1:


You should put a shorter time-out in the long polling response. Usually 30 seconds or less makes the trick. If within 30 seconds your server does not have data to send, it must send an empty response. The client will then issue a new request (immediately, or after a pause, depending on how much you want to reduce latency; for example, in Lightstreamer by default we don't use any pause between long-polling cycles).



来源:https://stackoverflow.com/questions/11430841/what-is-the-best-way-to-automatically-reestablish-long-polling-request

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