package controllers import ( beego "github.com/beego/beego/v2/server/web" "github.com/gorilla/websocket" "time" ) type MySocketController struct { beego.Controller } var upgrader = websocket.Upgrader{ ReadBufferSize: 1024, WriteBufferSize: 1024, HandshakeTimeout: 10 * time.Second, } type RecvWs struct { Type int `json:"T_type"` // 必填 1 订阅SN数据 2 解绑SN数据 3 项设备发送数据 Sn string `json:"T_sn"` // 必填 Password string `json:"T_ckey"` // 必填 Json map[string]interface{} `json:"T_json"` // Type == 3 时 必填 } // NGINX 超时配置 // proxy_connect_timeout 4s; // proxy_read_timeout 120s; // proxy_send_timeout 120s; func init() { //go SubClinetsClear() } //循环清理 //func SubClinetsClear() { // for true { // SubClinetsClearMap := make(map[*websocket.Conn]bool) // time.Sleep(time.Second * 10) // lib.SubClinets.Range(func(key, value interface{}) bool { // ConnList := value.([]*websocket.Conn) // Sn := key.(string) // logs.Println("SubClinets|", Sn, len(ConnList)) // for _, v := range ConnList { // if _,ok :=SubClinetsClearMap[v];!ok{ // logs.Println("Websocket 心跳|", fmt.Sprintf("%p", v)) // lib.WebsocketWriteJSON(v,"") // } // } // // return true // }) // // } //}