views:

154

answers:

2

Hi,

I'd like to create a websocket server within one of my C++ programs.

Do any standalone C++ libraries exist for creating websockets or is the only option to get the WebKit or V8 sources and extract their implementation?

A: 

Maybe using or digging in the code of CPPCMS might help?

Or you could check boost::asio.

edit> In fact boost::asio alone isn't enough but you could use cpp-netlib that is based on asio and is meant to be proposed to be in boost as boost::network.

Klaim
After skimming through the sources of CPPCMS it doesn't seem to support websockets and then I'd prefer using the V8 or WebKit implementation if no standalone library exists. Boost::asio seems to be for 'standard' networking and according to this post http://stackoverflow.com/questions/1894469/boost-asio-and-web-sockets there is no websocket implementation using it.
MKroehnert
Too bad... I thought there was an implementation provided with asio but there don't seem so. I'll let the answer as is for people to know about your conclusions.
Klaim
No problem and thanks for your answer.
MKroehnert
I just read about cpp-nelib on the boost mailing list and added it to my answer. Maybe that will help.
Klaim
Thanks again. But cpp-netlib seems a bit unpractical currently as it pulls in other boost dependencies and isn't finalized yet. Maybe I'll look into it again once it has been accepted by boost. For now kanaka's answer seems to fit better as wsproxy seems relatively small and easy to integrate.
MKroehnert
No problem. It seems from what I've read in the boost mailing list that cppnetlib will manage websockets in future versions but it don't yet anyway.
Klaim
+2  A: 

If you are specifically wanting to make a WebSockets server (as opposed to a client), then noVNC (a HTML5 VNC client) contains a C (and python) utility named wsproxy which is a WebSockets to generic TCP proxy. You could convert the WebSockets half to C++ pretty easily (or just build websocket.c into a static library and use it in a C++ server).

WebSockets is pretty easy to implement in a language that has plain socket libraries already. It's just a special handshake to begin and '\x00...\xff' framing of each packet.

Disclaimer: I made noVNC and wsproxy.

kanaka
Thanks, this seems to be the most practical way for now. I'll give it a try to see how it works.
MKroehnert