一箭落旄头
2018-12-09 14:28
func (conn *Connection)writeLoop() {
var (
data []byte
err error
)
select {
case data = <-conn.outChan:
if err = conn.wsConnect.WriteMessage(websocket.TextMessage , data); err != nil{
goto ERR
}
case <-conn.closeChan:
goto ERR
}
//for{
//
fmt.Println("发送1:",data )
data = <- conn.outChan //第一次堵塞在这里 因为此时conn.outChan 为空
fmt.Println("发送2:",data)
// if err = conn.wsConnect.WriteMessage(websocket.TextMessage , data); err != nil{
// goto ERR
// }
//
//
//}
ERR:
conn.Close();
}当第一次发送消息时 会被 select 检测到 outChan ,当执行到for 时 outChan 时就变空的了,会堵塞起来,导致一次无法正常发送消息。
实在看不出有什么问题,兄弟你的理解有误差吧。第一次发送消息不是放在管道里面吗?而且forloop比发送之前休先初始化,此时你发送消息放在管道里面了,而forloop不久读出来了吗??
GO实现千万级WebSocket消息推送服务
21483 学习 · 59 问题
相似问题