websocket handshake
websocket handshake
我正在使用c++编写一个websocket服务器,我在握手中挂起了使用chrome 17作为客户端。
当服务器向客户端发送握手响应时,chrome总是在控制台中显示以下错误:
WebSocket握手期间出错:Sec-Webocket Accept 不匹配
chrome中的事件如下:
t=1328796971951 [st= 5] WEB_SOCKET_SEND_REQUEST_HEADERS
--> GET / HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: 127.0.0.1:38950
Origin: null
Sec-WebSocket-Key: zMb+UCeRb+2OmMp9fpbxHw==
Sec-WebSocket-Version: 13
t=1328796971951 [st= 5] SOCKET_STREAM_SENT
t=1328796971971 [st=25] SOCKET_STREAM_RECEIVED
t=1328796971971 [st=25] WEB_SOCKET_READ_RESPONSE_HEADERS
--> HTTP/1.1 101 Switching Protocols
Upgrade: WebSocket
Connection: Upgrade
Sec-WebSocket-Accept: 4emBYsdkl0SxeUMGLNc0dFsI1/E=
t=1328796971972 [st=26] -REQUEST_ALIVE
请帮忙。
未正确计算Sec-WebSocket-Accept
值。
如何计算值(伪代码):
// Getting the Sec-WebSocket-Key from the Request header
var sec_Websocket_Key = requestHeader["Sec-WebSocket-Key"];
// Adding the magic string to sec_Websocket_key
// sha1 hash this new value
var sec_Websocket_Key_Hash = (sec_Websocket-Key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").sha1();
// Get the Base64 String of the hash
var sec_Websocket_Accept = sec_Websocket_Key_Hash.toBase64String();
// sec_Websocket_Accept now is the correct value to set in the Header
在此处获取更多信息
相关文章:
- Websocket++ 错误:收到错误handle_transport_init TLS 握手失败
- 如何使用 boost beast websocket 客户端收听 websocket feed?
- Boost (Beast) websocket:同步写入挂起
- boost beast Websocket Multi Request Server/Client 并不是真正的 mul
- 提升 Websocket 并io_context可重用性,以实现连接的可重新建立性
- 使用websocket时消息被延迟
- Websocket 客户端在 C++ 中使用 boost::Beast - 在写入操作时抛出错误
- 在QT中的两个窗口之间共享websocket连接
- 断开连接后重新连接boost beast(asio)websocket和http连接时出错
- 为什么Boost Variant使用模板构造函数而不是Boost::beast::websocket::stream的移
- boost beast websocket服务器也接受http连接
- 与Poco库的Websocket连接
- Aysnc 处理程序用于 POCO Websocket 中的传入消息
- C++ WebSocket 帧发送会导致服务器关闭连接
- Boost::Beast Websocket Bidirection Stream (C++)
- 如何在 Boost::Beast 上继续使用 websocket?
- WebSocket++服务器结束,但端口显示仍在使用中
- 通过QT WebSocket将OpenCV Mat Image发送到HTML客户端
- Poco Websocket投掷错误的URL例外.为什么
- websocket handshake