Ai
1 Star 0 Fork 0

pkuwwt/go-socket.io-client

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test.go 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
wwt 提交于 2024-11-29 13:35 +08:00 . fix: try transports one by one
package main
import (
"bufio"
"log"
"os"
"time"
socketio_client "gitee.com/pkuwwt/go-socket.io-client"
)
func main() {
opts := &socketio_client.Options{
Transports: []string{"polling", "websocket"},
Query: make(map[string]string),
}
opts.Query["uid"] = "1"
opts.Query["cid"] = "conf_123"
uri := "http://192.168.1.70:9090"
client, err := socketio_client.NewClient(uri, opts)
if err != nil {
log.Printf("NewClient error:%v\n", err)
return
}
client.On("error", func() {
log.Printf("on error\n")
})
client.On("connection", func() {
log.Printf("on connect\n")
})
client.On("message", func(msg string) {
log.Printf("on message:%v\n", msg)
})
client.On("disconnection", func() {
log.Printf("on disconnect\n")
})
go func() {
authStr := "{\"uid\":\"" + opts.Query["uid"] + "\",\"cid\":\"" + opts.Query["cid"] + "\"}"
for {
err := client.Emit("authenticate", authStr)
if err != nil {
log.Printf("Emit auth error:%v\n", err)
}
time.Sleep(10 * time.Second)
}
}()
reader := bufio.NewReader(os.Stdin)
for {
data, _, _ := reader.ReadLine()
command := string(data)
err := client.Emit("message", command)
if err != nil {
log.Printf("Emit message error:%v\n", err)
continue
}
log.Printf("send message:%v\n", command)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pkuwwt/go-socket.io-client.git
git@gitee.com:pkuwwt/go-socket.io-client.git
pkuwwt
go-socket.io-client
go-socket.io-client
8b8289f62f0d

搜索帮助