dongsha1544
2018-10-19 08:09
浏览 180
已采纳

Golang WebSocket数据不正确

I'm using x.net.websocket to read data from a websocket. The data is relatively large. When I read it, I can't read it completely, so it is cut off. Is there any way to solve it?

func receiveWebsocket(ws *websocket.Conn) error {
    for {
        var msg = make([]byte, 1024*1024) // 1024kb
        m, err := ws.Read(msg) 
        if err != nil {
            log15.Error("ws read error", "error", err)
            return err
        }
        fmt.Println("length ---",m,  string(msg))
        response := string(msg[:m])
        assignmentWebsocket(response)
    }
}

According to the log, the m value is always 4092, even if msg is very large.

图片转代码服务由CSDN问答提供 功能建议

我正在使用 x.net.websocket </ code>从websocket读取数据。 数据比较大。 当我阅读它时,我无法完全阅读它,因此它被切断了。 有什么方法可以解决? </ p>

  func receiveWebsocket(ws * websocket.Conn)错误{
 for {
 var msg = make([] byte,1024 * 1024)// 1024kb 
m,  err:= ws.Read(msg)
如果err!= nil {
 log15.Error(“ ws读取错误”,“ error”,err)
返回err 
} 
 fmt.Println(“ length  ---“,m,字符串(msg))
响应:=字符串(msg [:m])
分配Websocket(响应)
} 
} 
 </ code> </ pre> 
 \  n 

根据日志,即使 msg </ code>非常大, m </ code>值始终为4092。</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题