Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C or C++ library for encoding and decoding websocket frames

I have my own socket implementation that supports connection from regular tcp client. Now I would like to add websocket support in my server program. In that case I will need to support handshaking and message framing protocols that are supported by major web browsers. I was able to handle the handshaking part, but was stuck in dealing with the framing and un-framing of the messages. Is there any existing C or C++ library that handles the encoding and decoding of the websocket message frames, and supports the major websocket protocols used by the major web browsers?

Most of the current implementation that I found (i.e. libwebsocket, websocketpp, etc) implement their own server and client library, which means that I need to use their socket implementation. I don't want to do that because this will require me to modify a lot of things in my current program, and it is not an option for me. What I need is just a simple library that handles the encoding and decoding of the websocket frames (and/or also handle the handshaking part, but it is not compulsory).

like image 961
all_by_grace Avatar asked Dec 17 '22 03:12

all_by_grace


2 Answers

Websocketpp library author here.

The frame processing and handshake processing code is completely separate from the socket/network code. Look at the processors folder of the policy-refactor branch. There is one for draft 76 (hybi_legacy) and one for RFC6455 (hybi/hybi_header). The frame processors read from an STL stream that you can fill via your own network code or from some other source.

Send me a PM on github if you have any more specific questions.

like image 128
zaphoyd Avatar answered Mar 22 '23 23:03

zaphoyd


The websocketpp library is nice designed and the frame handling classes are not mixed with socket ones. There is dependency on the BOOST and STL libraries. STL is not a problem and the BOOST dependency is quite easy to avoid. Just start from the websocket_frame.hpp file of the policy-refactor branch.

like image 31
megabyte1024 Avatar answered Mar 22 '23 23:03

megabyte1024