wslay icon indicating copy to clipboard operation
wslay copied to clipboard

Upgrading HTTP to WebSocket

Open veselov opened this issue 8 years ago • 1 comments

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.

veselov avatar Jan 14 '17 01:01 veselov

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

tatsuhiro-t avatar Jan 14 '17 02:01 tatsuhiro-t