How to realize websocket client with gobwas
This article mainly explains "how to achieve websocket client with gobwas". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to achieve websocket client with gobwas".
Import ("context"fmt"net/url"github.com/gobwas/ws"github.com/gobwas/ws/wsutil") func main () {u: = url.URL {Scheme: "ws", Host: "192.168.1.24" Path: "/ dss/websocket/robot"} fmt.Println (u.String ()) ctx: = context.Background () conn, _, err: = ws.Dial (ctx, u.String ()) fmt.Println ("aaaa") / / dialer.Dial (u.String () Nil) if err! = nil {/ / handle error fmt.Println (err)} / /. / send message err = wsutil.WriteClientMessage (conn, ws.OpText, [] byte (`{"uuid": "501437093474467840", "wsMsgType": "REGISTER", "modules": "", "data": {"code": 4000, "reason": "the clientId already connected"}, "clientId": "aaa" "date": 1599718384966} `) if err! = nil {/ / handle error fmt.Println (err)} / /. / / receive message for {msg, _, err: = wsutil.ReadServerData (conn) fmt.Println (string (msg)) if err! = nil {/ / handle error fmt.Println (err)}} so far I believe you have a deeper understanding of "gobwas how to achieve websocket client", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!