完善ws
This commit is contained in:
@@ -134,24 +134,25 @@ func (c *EventController) TestWebsocket() {
|
|||||||
|
|
||||||
c.EnableRender = false //Beego不启用渲染
|
c.EnableRender = false //Beego不启用渲染
|
||||||
|
|
||||||
var s *model.ImMessageRecord
|
var s model.ImMessageRecord
|
||||||
for {
|
go func() {
|
||||||
//接收客户端的消息
|
for {
|
||||||
err := ws.ReadJSON(&s)
|
//接收客户端的消息
|
||||||
if err != nil {
|
err := ws.ReadJSON(&s)
|
||||||
globals.SugarLogger.Debugf("页面可能断开啦 ws.ReadJSON error: %v", err.Error())
|
if err != nil {
|
||||||
delete(clients, ws) //删除map中的客户端
|
globals.SugarLogger.Debugf("页面可能断开啦 ws.ReadJSON error: %v", err.Error())
|
||||||
break //结束循环
|
delete(clients, ws) //删除map中的客户端
|
||||||
} else {
|
break //结束循环
|
||||||
//把消息 写入通道
|
} else {
|
||||||
broadcast <- s
|
broadcast <- &s
|
||||||
//接受消息 业务逻辑
|
//接受消息 业务逻辑
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
dao.WrapAddIDCULDEntity(&s, "")
|
dao.WrapAddIDCULDEntity(&s, "")
|
||||||
dao.CreateEntity(db, &s)
|
dao.CreateEntity(db, &s)
|
||||||
// fmt.Println("接受到从页面上反馈回来的信息 ", utils.Format4Output(s, false))
|
// fmt.Println("接受到从页面上反馈回来的信息 ", utils.Format4Output(s, false))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
Reference in New Issue
Block a user