writeLoop方法有问题?
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 时就变空的了,会堵塞起来,导致一次无法正常发送消息。