7 Star 53 Fork 26

ryanduan / wsPool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
publicApi_test.go 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
ryanduan 提交于 2020-04-22 11:43 . 提升连接池的稳定性和并发量
package wsPool
import (
"log"
"testing"
"time"
)
func TestNewClient(t *testing.T) {
InitWsPool(func(err interface{}) {
log.Println(err)
})
for i:=0;i<1000 ;i++ {
go func() {
conf:=&Config{
Id:string(i),
Type:"robot",
Channel:[]string{"1","2","3"},
Goroutine:10,
}
connOjb:=NewClient(conf)
connOjb.OnOpen(func() {
log.Println("用户ID",connOjb.Id,"连接成功!")
})
//ws连接的事件侦听
connOjb.OnMessage(func(msg *SendMsg) {
log.Println(connOjb.Id,"收到消息",msg.GetCmd())
})
connOjb.OnPing(func() {
log.Println("收到连接的Ping",connOjb.Id)
//cache.PageApiPool.Remove(connOjb.Id)
})
connOjb.OnPong(func() {
log.Println("收到连接的Pong",connOjb.Id)
//cache.PageApiPool.Remove(connOjb.Id)
})
connOjb.OnClose(func() {
log.Println("连接己经关闭",connOjb.Id)
})
connOjb.OnError(func(err error) {
log.Println("连接",connOjb.Id,"错误信息:",err)
})
connOjb.OpenClient(nil,nil,nil)
time.Sleep(10*time.Second)
connOjb.Close()
}()
}
}
Go
1
https://gitee.com/rczweb/wsPool.git
git@gitee.com:rczweb/wsPool.git
rczweb
wsPool
wsPool
v1.1.8

搜索帮助