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