php sec-websocket-accept,消失的Sec-WebSocket-Key

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不到的时候截断了。

希望这篇文章能够帮助到有需要的人。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值