Send a message from the server to update the client automatically

blov · · 576 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>What I am trying to do is automatically send data from the server to the client without the clients having to request it. </p> <p>Example: Data is changed in a database the server can send that updated info to the client automatically.</p> <p>Would some part of AJAX work for that? I believe websockets can handle that, and that is an option<del>, but I do not want to have a constant open connection</del>. </p> <p>If this helps: The server is written in golang, and client javascript (most likely Angular, but not married to that framework)</p> <hr/>**评论:**<br/><br/>falien: <pre><p>Server Sent Events (EventSource) <a href="https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events">https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events</a> Or websockets.</p></pre>dtoebe: <pre><p>Fantastic! I did not know about this. I will do some research in to it.</p></pre>dtoebe: <pre><p>For any one else looking at this as a reference: <a href="http://caniuse.com/#feat=eventsource" rel="nofollow">http://caniuse.com/#feat=eventsource</a></p></pre>bioneuralnet: <pre><p>SSE are quite easy to implement with just net/http. They have some advantages over WebSockets, but one possible big downside is absolutely no IE or Edge support. I recently abandoned a beautifully simple SSE go server in favor of a more complex WebSockets one just for IE :(</p></pre>smilesbot: <pre><p>Look up! Space is cool! :)</p></pre>mirithil: <pre><p>My gut reaction is that I would use websockets. Any reason why you don&#39;t want a constant connection?</p></pre>dtoebe: <pre><p>No... I edited my post. A constant connection should be fine. I must have been thinking about the issues I had a few years ago with web sockets when it was more &#34;bleeding edge&#34;. I just want to see what other options I may have.</p></pre>Spirit_of_Stallman: <pre><p>SSE and <a href="https://github.com/antage/eventsource" rel="nofollow">eventsource</a> package. </p></pre>

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

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