帶有gorilla / websocket軟體包的WebSocket教程



●訂閱即可觀看更多我的視頻,並點擊該「贊」按鈕以支持該頻道!

實時聊天應用課程-https://tutorialedge.net/projects/chat-system-in-go-and-react/
文字教學-https://tutorialedge.net/golang/go-websocket-tutorial/

嗨,各位開發人員!在本教程中,我們將研究如何在我們自己的基於Go的程序中使用WebSockets做一些很酷的實時工作。

在本教程結束時,我們應該已經介紹了以下內容:

*什麼是WebSocket
*如何在Go中構建簡單的WebSocket應用程序

就本教程而言,我們將使用gorilla / websocket軟體包,因為我在一些生產應用程序中親自使用了gorilla / websocket軟體包,並取得了巨大的成功。

我的設置:https://tutorialedge.net/uses/
給我買杯咖啡:https://www.buymeacoffee.com/tutorialedge
Patreon:https://www.patreon.com/tutorialedge

●我的Twitter►⁦‪https://twitter.com/Elliot_f
●我的網站►https://tutorialedge.net。

13 comments
  1. A slight update to the code – Move the CheckOrigin check to the upgrader struct so that there isn't a data race:

    var upgrader = websocket.Upgrader{
    ReadBufferSize: 1024,
    WriteBufferSize: 1024,
    CheckOrigin: func(r *http.Request) bool { return true },
    }

  2. Great video! I had a couple issues though when following this tutorial. I ended up having to setup a reverse proxy to change the protocol to "ws" when my client was accessing the ws endpoint route. Without that I continuously got a "unexpected response code 200" error. The server didn't send a 101 response on its own.

    After using nginx I was able to resolve that, but I now keep getting "WebSocket connection to 'ws://127.0.0.1/ws' failed: Connection closed before receiving a handshake response". I am running this on my localhost, fyi. Any ideas?

  3. I have a question. How gorilla/websocket Package can create a websocket with some event, emit from client to server, server to client like Socket.IO on Nodejs? Now, I'm meaning gorilla/websocket package can't emit to special client, can't get event from client( like on("some event") ) to handle special function for that event. Pls help.

  4. Awesome video! Many links online about Hello World with websockets just didn't work. I didn't get it working until this awesome video which does exactly what it says. Cheers!

  5. Didnt watched it right now, but currently am into this topic. Next video, please incorporate gRPC protocol buffers. Like.. receive nested JSON from WebSocket and Unmarshall into ProtoBuf and back – feed protobuf into websocket as JSON. 🙂

Comments are closed.