删除连接的tcp客户

pull/30/head
taoshihan1991 4 years ago
parent 5507195c71
commit 08eff50ce1

@ -1,6 +1,7 @@
package controller package controller
import ( import (
"github.com/gin-gonic/gin"
"log" "log"
"net" "net"
) )
@ -29,8 +30,22 @@ func PushServerTcp(str []byte){
_,err:=conn.Write(str) _,err:=conn.Write(str)
log.Println(ip,err) log.Println(ip,err)
if err!=nil{ if err!=nil{
conn.Close()
delete(clientTcpList,ip) delete(clientTcpList,ip)
//clientTcpList=append(clientTcpList[:index],clientTcpList[index+1:]...) //clientTcpList=append(clientTcpList[:index],clientTcpList[index+1:]...)
} }
} }
}
func DeleteOnlineTcp(c *gin.Context) {
ip:=c.Query("ip")
for ipkey,conn :=range clientTcpList{
if ip==ipkey{
conn.Close()
delete(clientTcpList,ip)
}
}
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
})
} }

@ -104,6 +104,7 @@ func main() {
engine.GET("/mysql",middleware.JwtApiMiddleware,middleware.RbacAuth, controller.MysqlGetConf) engine.GET("/mysql",middleware.JwtApiMiddleware,middleware.RbacAuth, controller.MysqlGetConf)
engine.POST("/mysql",middleware.JwtApiMiddleware,middleware.RbacAuth, controller.MysqlSetConf) engine.POST("/mysql",middleware.JwtApiMiddleware,middleware.RbacAuth, controller.MysqlSetConf)
engine.GET("/visitors_online", controller.GetVisitorOnlines) engine.GET("/visitors_online", controller.GetVisitorOnlines)
engine.GET("/clear_online_tcp", controller.DeleteOnlineTcp)
engine.POST("/visitor",controller.PostVisitor) engine.POST("/visitor",controller.PostVisitor)
engine.GET("/visitor",middleware.JwtApiMiddleware, controller.GetVisitor) engine.GET("/visitor",middleware.JwtApiMiddleware, controller.GetVisitor)
engine.GET("/visitors",middleware.JwtApiMiddleware, controller.GetVisitors) engine.GET("/visitors",middleware.JwtApiMiddleware, controller.GetVisitors)

Loading…
Cancel
Save