This was rather
frustrating and time consuming to solve, so hopefully this will
help someone.
the 2nd parameter in
socket_read is the max
length to read from the headers. Why you
wouldn't want all the headers is beyond me. I noticed in many basic
tutorials of websockets that the second parameter was 1024, and I
didn't think to check the docs to see what the number was for.
Turns out, that number was just barely too low to work in my case.
I just upped the number considerably so it won't be a problem in
the future, and now it works great
so to be clear:
If this doesn't
work:
$header =
socket_read($socketNew, 1024); //read data sent by the socket
increase the max length to
read:
$header =
socket_read($socketNew, 5000); //read data sent by the socket
Once I changed the number
here (and every other place with a max length param) it worked
instantly.
=============================
回答者建议接受数据的缓冲区由1024增大到5000
但我们项目设置的缓存区是65500,而上面收到数据远小于这个数。暂时排除了这个可能性
但后面又找到一篇文章
发现 Sec-WebSocket-Key
的顺序并不都在Sec-WebSocket-Version之前,也有可能在 Cookie后面
联想到之前,部分玩家登陆在握手协议之后服务端有收到些莫名其妙的数据。
我们怀疑握手协议的数据应该有很大的可能性没有接收完!
后来证实数据确实没有接收完,但是数据却没有大于65500。erlang底层在收到1500不到的时候截断了。
希望这篇文章能够帮助到有需要的人。