在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:kljensen/golang-html5-sse-example开源软件地址:https://github.com/kljensen/golang-html5-sse-example开源编程语言:Go 90.8%开源软件介绍:Golang HTML5 SSE ExampleThis is an minimalistic example of how to do HTML5 Server Sent Events with Go (golang). From the server's perspective, SSE is nearly identical to long polling. The client makes a GET request that establishes a TCP connection. The server keeps this connection open and sends events to the client when they are available. In this example, the server pushes a new event every five seconds, consisting of a short message with the current time. Any number of clients can be connected: they will all receive the same events if they're connected concurrently. (This is achieved using Go's channels and a fan-out pattern. In other languages you may need to use some kind of pubsub messaging, like Redis or Zeromq.) The main advantage of HTML5 SSE over long polling is that there is a nice API for it in modern browsers, so that you need not use iframes and such. SSE is easier than Websockets in the sense that it communicates exclusively over HTTP and therefore does not require a separate server. Websockets, however, supports two-way real-time communication between the client and the server. InstallingCheck out the repository from GitHub
RunningTo run the server, do
Then point your web browser to
And, you should see output in the terminal like the following
ThanksThis code is based off of a few sources, mostly License (the Unlicense)This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to http://unlicense.org/ |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论