1 Star 0 Fork 0

小鱼儿小董子/dongli-zinx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
client.go 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
小鱼儿小董子 提交于 2025-01-14 22:07 +08:00 . first commit
package main
import (
"fmt"
"os"
"os/signal"
"time"
"gitee.com/wanjimao/dongli-zinx/ziface"
"gitee.com/wanjimao/dongli-zinx/zlog"
"gitee.com/wanjimao/dongli-zinx/znet"
)
// PongRouter pong test 自定义路由
type PongRouter struct {
znet.BaseRouter
}
// Handle Pong Handle
func (this *PongRouter) Handle(request ziface.IRequest) {
zlog.Debug("Call PongRouter Handle")
//先读取服务器返回的数据
zlog.Debug("recv from client : msgId=", request.GetMsgID(), ", data=", string(request.GetData()))
}
func wait() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
sig := <-c
fmt.Println("===exit===", sig)
}
func main() {
// Create a TLS client.
c := znet.NewTLSClient("127.0.0.1", 8899)
c.SetOnConnStart(func(connection ziface.IConnection) {
go func() {
for {
err := connection.SendMsg(1, []byte("Ping with TLS"))
if err != nil {
fmt.Println(err)
break
}
time.Sleep(1 * time.Second)
}
}()
})
c.AddRouter(2, &PongRouter{})
c.Start()
wait()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wanjimao/dongli-zinx.git
git@gitee.com:wanjimao/dongli-zinx.git
wanjimao
dongli-zinx
dongli-zinx
v0.0.1

搜索帮助