Stand alone websocket server

xuanbao · · 770 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>hello,</p> <p>I use the websocket protocol for internal process communication in my project and my code base is written in nodejs. I am actually using &#34;ws&#34; lib for server and client communication.</p> <p>However, I need to update a project written in go which should integrate a websocket server that could communicate with my other programs.</p> <p>Because, the clients that will connect to this websocket server will only use websocket protocol without any http connection, is there any lib that can handle this without any http server or origin verification? All the golang websocket servers llibraries that I have checked require a http handler.</p> <hr/>**评论:**<br/><br/>arschles: <pre><p>about a year ago, I built a net/rpc server to request/reply over websocket. the accept loop looks liked like this: import( &#34;code.google.com/p/go.net/websocket&#34; &#34;github.com/fsouza/go-dockerclient&#34; &#34;net/rpc&#34; &#34;net/rpc/jsonrpc&#34; )</p> <pre><code>func rpcLoop(wsConn *websocket.Conn) { handlers := NewHandlers() server := rpc.NewServer() server.Register(handlers) serverCodec := jsonrpc.NewServerCodec(wsConn) for { server.ServeCodec(serverCodec) } } </code></pre> <p>It worked reasonably, and I was able to use the standard net/rpc system to communicate over a websocket (via jsonrpc), which was nice. handlers was a struct that had some rpc-compatible funcs with it as their receiver.</p> <p>I spent only a few mins on this code a while ago and haven&#39;t touched it since, but I hope it helps a little bit at least</p></pre>tuxlinuxien: <pre><p>Awesome, it worked like a charm. I also use a json rpc like protocol so your snippet is even better.</p></pre>arschles: <pre><p>glad to hear it!</p></pre>Bulters: <pre><p>You can use the gorilla websocket library and setup the &#34;upgrader&#34; to not check the origin. </p></pre>tuxlinuxien: <pre><p>I have checked this lib already, but their api is not low level enough for me.</p></pre>

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

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