英文:
What is proper time span for GO websocket to keep-alive
问题
根据这个问题,在code.google.com/p/go.net/websocket
中,需要自己实现保持连接的功能。
那么,WebSocket保持活动状态的适当时间间隔是多久?谢谢!
英文:
As this question, In code.google.com/p/go.net/websocket
, it needs to implement keep-alive by self.
So what is proper time span that web-socket to keep alive? Thanks!
答案1
得分: 3
通常将保持活动连接的时间保持在60秒以下是一个好主意(例如,Heroku要求您至少每55秒发送一些数据)。因此,每50秒发送一次ping/pong应该可以保持您的连接活动。请注意,根据您的服务器堆栈、任何网络加速器、代理和缓存,您可能需要选择一个更短的间隔。NAT路由器也会影响间隔。大多数情况下,50秒的间隔都可以工作,但当50秒不起作用时,通常25秒就可以解决问题。
英文:
Generally keeping the keep-alive just under 60 seconds is good idea. (Heroku for instance requires you to send some data at least every 55 seconds) So sending a ping/pong every 50 seconds should keep your connection alive. Do note that you might have to choose a shorter interval depending on your server stack, any web accelerators, proxies and caches. A NAT router also influences the interval. Most of the time 50 seconds will work but 25 seconds usually does the trick when 50 doesn't.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论