tcptemplate/README.md

54 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

## go-tcpFramework-rudy
#### 介绍
基于golang的tcp长连接框架--rudy。
#### 软件架构
功能:
提供连接数管理,支持熔断,热重启
提供路由管理,支持context化timeout和cancel
支持分布式,和主节点选举
支持apolo配置
心跳包支持
服务端推送支持
#### How to use
```go
package main
import (
"flag"
"go-tcpFramework-rudy/config"
"go-tcpFramework-rudy/logger"
"go-tcpFramework-rudy/network"
"log"
)
func main() {
var confPath string
flag.StringVar(&confPath,"conf_path","TcpServConfig.json","the path of configuration file")
flag.Parse()
config.InitConfig(confPath)
//network.SetHandler(handler.HandlePack)
server := network.ServerFactory(config.Configs().Ipadress)
server.SetHandler(nil)
log.Print("start " + config.Configs().Type + " server " + "at address " + config.Configs().Ipadress)
e := server.Run()
if nil != e {
logger.LogDebugError(e.Error())
}
}
```
server 服务实例
server.SetHandler 设置处理句柄
server.Run() 服务启动
### 包头格式文档(Package format)
```text
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0x40 | 0x41 | length[3] | length[2]
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| length[1] | length[0] | verify |
```
包头格式7个字节首个字节标识符40 41 ,然后包长度最后是verify是包头长度的校验和