Is there a package like a http router, but for generic purposes or sockets?

agolangf · · 294 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I am working on a project that uses sockets for communication between multiple clients and a server. The sockets are used, because the clients can make a request to the server to perform a certain multi-step action and the server must provide feedback to the client after each step is completed. Essentially it is still similar to an http API, but done with sockets.</p> <p>My question is, is there a package that would work in a way similar to an http router like <a href="https://github.com/go-chi/chi" rel="nofollow">chi</a>, but for sockets or a general purpose one, that can be extended. </p> <p>For instance, one that takes a routing key (potentially containing parameters), which is a part of a socket message, and then efficiently finds the correct handler for that routing key using some well optimized data structure.</p> <p>Support for middlewares might also be interesting.</p> <p>I guess I could build my own package that does that, but I wanted to check first if there was an existing project.</p> <hr/>**评论:**<br/><br/>maddiez: <pre><p>I&#39;ve written something like this since I couldn&#39;t find any of the &#39;frameworks&#39; like you said, but my application is way more simple than the scenario you&#39;re describing, eventually I decided just write my own.</p> <p>IMHO, because there isn&#39;t a &#39;protocol&#39; between the client and server like HTTP do, I doubt that there would be anything like <code>chi</code>socket communication, as one would have to define some sort of &#39;protocol&#39; so it can provide mechanisms like &#39;routing keys&#39; or &#39;parameters&#39; like you&#39;ve mentioned. If that&#39;s the case, I would say there are some other already existing protocols that would work just fine over sockets, then why reinvent the wheel?</p> <p>FWIW I used <a href="https://github.com/firstrow/tcp_server" rel="nofollow">https://github.com/firstrow/tcp_server</a> as a template do work on, with some modifications to suit my need.</p> <p>Not a native speaker, sorry for my grammar if it&#39;s inappropriate :)</p></pre>bestfoodnearme: <pre><p>Last week I wrote a client / server framework where the server acts as a worker pool. Each server can handle a single type of job which is either some Go code or wraps an external command via the exec/cmd.</p> <p>I was going to make a REST interface, but I require tens of thousands of calls per hour so I opted to make its a simple protocol over TCP. I kept it simple to just three commands PING, WORK, and GET. I think it you really need to make it more generic in the CHI sense, you would have to use some form of generic text parser with a state machine. If you really do not need it, I would suggest just sticking with a small set of commands you can hand code.</p></pre>

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

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