Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize websocket client with gobwas

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report