1 Star 1 Fork 0

凡卡 / libp2parea

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
client_example.go 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
凡卡 提交于 2023-11-29 11:01 . first commit
package main
import (
"fmt"
"time"
"gitee.com/prestonTao/libp2parea/engine"
)
func main() {
example1()
}
var CryKey = []byte{0, 0, 0, 0, 0, 0, 0, 0}
func example1() {
engine.GlobalInit("console", "", "debug", 1)
engine.InitEngine("client_server")
engine.RegisterMsg(101, hello)
// engine.SetAuth(new(handlers.NoneAuth))
// engine.SetCloseCallback(handlers.CloseConnHook)
err := engine.Listen("127.0.0.1", int32(9982))
if err != nil {
panic(err)
}
nameOne, _ := engine.AddClientConn("127.0.0.1", int32(9991), false, engine.BothMod)
if session, ok := engine.GetSession(nameOne); ok {
data := []byte("hello")
session.Send(101, 0, 0, CryKey, &data)
}
nameTwo, _ := engine.AddClientConn("127.0.0.1", int32(9992), false, engine.BothMod)
if session, ok := engine.GetSession(nameTwo); ok {
data := []byte("hello")
session.Send(101, 0, 0, CryKey, &data)
}
time.Sleep(time.Minute * 10)
}
func hello(c engine.Controller, msg engine.Packet) {
fmt.Println(string(msg.Data), "client")
}
type FindNode struct {
Name string `json:"name"`
}
Go
1
https://gitee.com/prestonTao/libp2parea.git
git@gitee.com:prestonTao/libp2parea.git
prestonTao
libp2parea
libp2parea
58a2b3547940

搜索帮助