GO WebSocket保持活动的适当时间跨度是多久?

huangapple go评论95阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2014年5月15日 22:01:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/23680534.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定