wslay
wslay copied to clipboard
Upgrading HTTP to WebSocket
Hello.
Is there any good example code on how to easily upgrade an HTTP connection to a WS? AFAIU, WSLay should only be engaged after the connection is upgraded, but that does require nearly fully functional HTTP library...
Thank you.
Check out https://github.com/tatsuhiro-t/wslay/blob/6abacc1da10344d7d7b13c21edc76fcdf587de0c/examples/testclient.cc
It is design decision to make wslay know only about WebSocket framing layer. It allows for existing HTTP implementation to integrate wslay easily. Implementing HTTP upgrade for WebSocket does not require full functional HTTP library. It only requires HTTP header parser, and several header field inspections described as RFC 6455. There are several good HTTP header parsers:
- https://github.com/nodejs/http-parser
- https://github.com/h2o/picohttpparser