How do I go about writing websocket clients?

xuanbao · · 668 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;ve to implement a system where 100s-1000s of websocket clients will run forever on my server and connection to some servers. How do I go about managing all the clients? </p> <p>Is there something out there that&#39;ll let me write the clients as goroutines and easily manage them from the parent process? By manage, I mean the ability to close a connection, start new ones and restart the ones that die for some reason.</p> <p>Or should I use a traditional process manager (with an api) to launch and manage independent OS processes of the same go program and use a master go program to manage them from the process manage API?</p> <p>Update:</p> <p>tl;dr: How to write a websocket client pool to manage possibly thousands of websockets clients?</p> <hr/>**评论:**<br/><br/>mwholt: <pre><p>Why do you need to spawn new process? You can do it all in-process. Packages like <a href="http://godoc.org/golang.org/x/net/websocket" rel="nofollow">golang.org/x/net/websocket</a> or <a href="http://www.gorillatoolkit.org/pkg/websocket" rel="nofollow">gorilla/websocket</a> will help. Each ws connection already runs in its own goroutine.</p> <p>First try without a pool, then pool only if you have to. These packages are easy enough to use for moderate-load web servers (which is ~100s-1000s connections I&#39;m pretty sure) in my experience.</p></pre>hundley10: <pre><p>Check out this guy&#39;s implementation (the Hub it uses to manage connections). I based one of my servers off this example and it&#39;s been a lifesaver. Pretty easy to extend with timeouts, etc.</p></pre>asniper: <pre><p>What guy </p></pre>avrtno: <pre><p>Maybe this <a href="http://gary.burd.info/go-websocket-chat" rel="nofollow">guy</a>?</p></pre>Bromlife: <pre><p>You forgot the link yo. </p></pre>

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

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