golang语言实现socket服务端,解决粘包拆包问题,心跳超时检测.
//启动socket
func (server *SocketServer) Start() {
listener, err := net.Listen(server.Network, server.Address)
if err != nil {
server.OnError("Listen失败", err)
return
}
defer listener.Close()
fmt.Printf("socket 启动成功;Network=%s,Address=%s", server.Network, server.Address)
server.OnStart(server)
go server.CheckClient()
for true {
conn, err := listener.Accept()
if err != nil {
server.OnError("Accept失败", err)
continue
}
if server.CurrentCli
1