zero – [152]
最后更新于:2022-04-02 02:50:35
[TOC]
> [参考](https://github.com/9b9387/zero)
## 概述
具有心跳的轻量级套接字服务,可以轻松地用于TCP服务器开发中。
## 安装
```
go get -u github.com/9b9387/zero
```
```
import "github.com/9b9387/zero"
func main() {
host := "127.0.0.1:18787"
ss, err := zero.NewSocketService(host)
if err != nil {
return
}
// set Heartbeat
ss.SetHeartBeat(5*time.Second, 30*time.Second)
// net event
ss.RegMessageHandler(HandleMessage)
ss.RegConnectHandler(HandleConnect)
ss.RegDisconnectHandler(HandleDisconnect)
ss.Serv()
}
```
';