我有一個(gè)使用 websocket 連接到我的 goserver 的應(yīng)用程序。我使用此代碼創(chuàng)建了一個(gè) websocket 連接 - https://github.com/gorilla/websocket/tree/master/examples/chathttp.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) { serveWs(hub, w, r) })當(dāng)我收到一個(gè) POST 電話時(shí),我需要向所有設(shè)備廣播一條消息 - “訂單已收到:” productNum。在 post 請(qǐng)求中收到 productNum。http.HandleFunc("/post",BroadcastMessage())我想知道我需要在 BroadcastMessage() 中寫(xiě)什么來(lái)做到這一點(diǎn)。請(qǐng)幫忙。
1 回答

翻過(guò)高山走不出你
TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超3個(gè)贊
在 BroadcastMessage 中,向[]byte
集線器的廣播頻道發(fā)送一個(gè):
hub.broadcast <- message
- 1 回答
- 0 關(guān)注
- 257 瀏覽
添加回答
舉報(bào)
0/150
提交
取消