ymofen / diocp-v5

delphi iocp, http, websocket, ntrip
BSD 2-Clause "Simplified" License
238 stars 110 forks source link

WebSocket client #3

Closed r1me closed 6 years ago

r1me commented 6 years ago

TDiocpWebSocketTcpClient doesn't seem to be compatible with non DIOCP servers. For example while trying to connect to ws://echo.websocket.org, the server will return error 400 (bad request). This happens due to missing headers like Sec-WebSocket-Key and Sec-WebSocket-Version. I've tried to update the class by adding those headers in TDiocpWebSocketContext.PostWebSocketRequest, then server returned a valid handshake (101) but right after that closed the connection with close code 1002 (protocol error). I guess your implementation of WebSocket is based on first versions of this "protocol". Are you planning to update this class ?

ymofen commented 6 years ago

谢谢反馈,我将用ws://echo.websocket.org 来调试Diocp的客户端类。

r1me commented 6 years ago

Thanks, I've made a patch and I hope it will be helpful in solving the issue. With the patch it passes upgrade to WebSocket (server returns valid handshake): https://github.com/r1me/diocp-v5/commit/55dd7b74dd63c7aaa65888d7c66b4c0c909be7f7

HTTP/1.1 101 Web Socket Protocol Handshake
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: content-type
Access-Control-Allow-Headers: authorization
Access-Control-Allow-Headers: x-websocket-extensions
Access-Control-Allow-Headers: x-websocket-version
Access-Control-Allow-Headers: x-websocket-protocol
Access-Control-Allow-Origin: echo.websocket.org
Connection: Upgrade
Date: Wed, 27 Dec 2017 12:17:11 GMT
Sec-WebSocket-Accept: N6RXLen0Bm6yVjpcC322KTdMD7Q=
Server: Kaazing Gateway
Upgrade: websocket

But then server closes connection with error 1002, probably due to missing ping/acknowledgment ?

PS. I/O Completion Ports are awesome :-)

ymofen commented 6 years ago

已经修复,请再测试一下

r1me commented 6 years ago

Works as intended. Thank you. :+1: