代码拉取完成,页面将自动刷新
package cluster
import (
"gitee.com/lichun-123/leaf/conf"
"gitee.com/lichun-123/leaf/network"
"math"
"time"
)
var (
server *network.TCPServer
clients []*network.TCPClient
)
func Init() {
if conf.ListenAddr != "" {
server = new(network.TCPServer)
server.Addr = conf.ListenAddr
server.MaxConnNum = int(math.MaxInt32)
server.PendingWriteNum = conf.PendingWriteNum
server.LenMsgLen = 4
server.MaxMsgLen = math.MaxUint32
server.NewAgent = newAgent
server.Start()
}
for _, addr := range conf.ConnAddrs {
client := new(network.TCPClient)
client.Addr = addr
client.ConnNum = 1
client.ConnectInterval = 3 * time.Second
client.PendingWriteNum = conf.PendingWriteNum
client.LenMsgLen = 4
client.MaxMsgLen = math.MaxUint32
client.NewAgent = newAgent
client.Start()
clients = append(clients, client)
}
}
func Destroy() {
if server != nil {
server.Close()
}
for _, client := range clients {
client.Close()
}
}
type Agent struct {
conn *network.TCPConn
}
func newAgent(conn *network.TCPConn) network.Agent {
a := new(Agent)
a.conn = conn
return a
}
func (a *Agent) HandleMsg(data []byte) {}
func (a *Agent) OnClose() {}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。