How to send to only one client and not all clients using Go and gorilla websocket -


i trying learn websockets go. have been looking @ examples gorilla websocket.

i have checked out these 2 examples show how use gorilla websocket:

https://github.com/gorilla/websocket/tree/master/examples

https://www.youtube.com/watch?v=ysaz_oqpoo0

all of these examples show how connect websocket server, send , receive texts. don't understand how can send 1 client. because in real world application have users, , don't want users receive same message , same data. there way me unique id of connection can save in database redis , link user id in same database, , use websocket id send specific client if user id received message or notification? how 1 go , achieve this? if case, how that?

is there way me unique id of connection can save in database redis , link user id in same database, , use websocket id send specific client if user id received message or notification?

sure! can generate id while user registering. add userid field in connection structure

in chat example have hub, contains connections pool. pool using broadcast messages users:

case m := <-h.broadcast:     c := range h.connections {         select {         case c.send <- m:         default:             close(c.send)             delete(h.connections, c)         }     } } 

so there go. should make method send private message, depend on userid


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -