C++window环境下实现WebSocket 同时避免failed: A server must not mask any frames that it sends to the client.

本文主要是使用C++ 在window环境下 实现WebSocket Server端的经验记录, 不对WebSocket做详细解释

关于详细细节可以参考如下几篇文章

https://blog.csdn.net/xiaoquantouer/article/details/58001960  代码来源, 基于此博主的代码进行修改完成

https://blog.csdn.net/weixin_34196559/article/details/83479894  此博主已经对原理解释的非常详细了,强烈推荐仔细阅读,本人就是在详细阅读后来改完的代码

https://www.jianshu.com/p/2fc4d76457e3 WebSocket抓包方法

https://www.cnblogs.com/songwenjie/p/8575579.html  大牛分析的WebSocket包细节

https://datatracker.ietf.org/doc/rfc6455/?include_text=1  英文协议

关于本人遇到的坑,最坑的就是failed: A server must not mask any frames that it sends to the client.  

这个错误爆出的原因网上有两种说法

1. 在握手结束的时候多了一个  "\0"(本人没有遇到)

2. 服务端在响应客户端的时候mask配置为了true(本人遇到了)

关于在下项目的包截图如下

这是第一个回复客户端的包, 可以看到mask是false

C++window环境下实现WebSocket 同时避免failed: A server must not mask any frames that it sends to the client.

这是第二次回复时候的数据包 mask为true!!!!!  这就是失败的原因, 因为根据协议规定 客户端发送给服务端 mask为true 也就是数据要加密  服务端回复客户端不允许加密 mask 必须为false  关于为什么会这样 还没弄清楚 因为第一次使用C++语言可能是不熟练导致的

C++window环境下实现WebSocket 同时避免failed: A server must not mask any frames that it sends to the client.

源码: https://pan.baidu.com/s/1VspFvz_P-pZgrBzX0cCqoQ   g2gk

代码只是实现了基本的功能, 此贴先记录下基本功能, 后期再 详细写一下