Windows websockets timeout

polaris · · 501 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;ve ran into some strange websockets behaviour today and seek for some help from comunity to understand what can be the cause.</p> <p>I&#39;ve been trying to implement some simple webservice using websockets (from gorillas toolkit). Everything worked fine at home (I&#39;m using macOS there), but when I pulled the latest version from git at the office (we have Windows here) - I was surprised to see that the very same code gives different result. After some time connection timeouts, pushing all messages to the client, and closes.</p> <p>After some meddling with my code I couldn&#39;t figure out what was wrong and decided to test gorilla&#39;s chat example (<a href="https://github.com/gorilla/websocket/tree/master/examples/chat" rel="nofollow">https://github.com/gorilla/websocket/tree/master/examples/chat</a>)</p> <p>Same behavior. You send some messages to chat, no reaction, 60 seconds after - you finally see:</p> <pre><code>test1 test2 test3 Connection closed. </code></pre> <p>Any ideas what can cause this? </p> <p>My repo (just in case): <a href="https://github.com/konart/gokoi/tree/websockets" rel="nofollow">https://github.com/konart/gokoi/tree/websockets</a></p> <hr/>**评论:**<br/><br/>konart: <pre><p>Okay I figured it out. All ports except for 15000 are closed. </p> <p>Mark as SOLVED. :)</p></pre>SilentWeaponQuietWar: <pre><p>the <strong>ListenAndServe</strong> method doesn&#39;t let you explicitly set timeouts and other config settings. For that very reason, it&#39;s usually suggested to use <strong>http.Server</strong> instead</p> <p><a href="https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/" rel="nofollow">https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/</a></p></pre>konart: <pre><p>I don&#39;t think this is the case though. First of all timeout happens after 60 seconds, so I believe this is the &#34;// Time allowed to read the next pong message from the peer.&#34; or a &#34;pongWait&#34; variable that is used for setting ReadDeadline and PongHandler.</p> <p>Anyway - I&#39;ve tried doing it this way before (just in case):</p> <pre><code>srv := &amp;http.Server{ Handler: r, Addr: &#34;127.0.0.1:8000&#34;, WriteTimeout: 15 * time.Second, ReadTimeout: 15 * time.Second, } log.Fatal(srv.ListenAndServe()) </code></pre> <p>Same outcome.</p></pre>daveddev: <pre><p>If you are using a reverse proxy to pass off processing, you may be running into a timeout defined as a default within that system. This came up as a problem for me recently (nginx - proxy_read_timeout). I hope this helps.</p></pre>konart: <pre><p>Thanks, I&#39;m gonna keep it in mind, but for now - I figured it out. Blocked ports were the problem</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

501 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传