I have been trying to find a simple C++ WebSocket client that is draft 08+ compatible. I have been able to find some server implementations, but that is not what I need. I need a client, hopefully with no extra stuff like server implementation to keep it small and clean and easy to build with as less dependencies as possible.
It has to be 08+ version compatible (Firefox 6+, Chrome 14+).
Do I need to implement it myself or have I missed a great library?
Related
I am trying to create a signal/textsecure client using qt and C++, however i cant seem to fibd any C++ bindings for it.
the only bindings i can find are for Go (https://github.com/nanu-c/textsecure/)
is there any way to connect C++ with signal?
edit:
i wanted to clarify some things:
-im talking about the messaging app called Signal (https://signal.org)
-i am trying to write an app for ubuntu touch and am developing on manjaro linux.
On Linux or Unix, you probably want to communicate with other remote applications using some communication protocol, such as HTTP or HTTPS or SOAP or JSONRPC or ONCRPC. Of course read about socket(7) and before that Advanced Linux Programming then about syscalls(2). Consider reading a textbook on Operating Systems
Be sure to study the source code related to Signal. Read their technical documentation.
You surely need to understand the details. So take a few days or weeks to read more about them.
If you want to use some web service, you need to read and understand its documentation and when and how you are allowed to use it. There could be legal or financial issues.
Then you might use HTTP related libraries (e.g. Wt or libonion server side, and libcurl or curlpp client side).
See also in April 2020 the ongoing HelpCovid free software project (for Linux), at least for inspiration. We are coding it in C++.
after a little more digging i found that textsecure bindings are now renamed to libsignal.
after finding that out i found a lib for c/c++
https://github.com/signalapp/libsignal-protocol-c
I'm looking to grab the source of a webpage and add it to a string, all the guides I see though use curl or winsockets and I need this to be cross-compatible and use C++ only (No external libraries)
Could anyone point me in the right direction please?
Thanks.
You may want to check boost::asio. It offers cross-platform networking, which will cover TCP/IP. boost is not a standard library, but it's de facto second standard C++ library. BTW, a lot of boost stuff ends up in std.
Next thing is HTTP client. Unfortunately, standard C++ library doesn't have HTTP client, but a basic, partial implementation of the protocol is simple enough that you can try to roll your own - you'll probably need only GET request. Try sending GET request over telnet, by typing it manually - you'll see it's very simple.
If SSL/TLS or a complete HTTP support is required, you may be forced to use a 3rd party library, because implementing them is a more than a challenging task.
For C++ only without an external library? No such thing.
Qt is fairly cross platform, supporting Windows, Linux, MacOS, Android, iOS and a bunch of other more exotic platforms, plus embedded.
Qt 4 had a dedicated QHttp class, but it got deprecated and removed in Qt 5. With Qt 5 you will have to use the QNetworkAccessManager class:
A simple download off the network could be accomplished with:
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://qt-project.org")));
True, Qt 5 is a big framework, hardly justified for the purpose of that single task, but on the other hand, it is very powerful, very portable application development framework, so odds are it may come in handy in other aspects as well.
I have many legacy C libraries used for numerical analysis and scientific computing (e.g. simulation) that I want to use in a web application I am building (so far I have only been using Javascript to make a user interface). What options do I have in doing this on the client side and/or the server side? I heard about using native client with chrome, but I dislike that the client has to turn on the native client flag to do this.
On Server Side:
To begin with CGI (Common Gateway Interface) is the most basic method to be able to use native C libraries in a web application - wherein you delegate an executable (say written in C) to generate the sever side web content.
But CGI is very primitive and inefficient. Each command can result in creation of a new Process on the server. Thus here are other viable alternates:
Apache Modules let you run third party software within the web server itself.
FastCGI - Single Process handles more than one user request.
SCGI - Simple CGI
Refer: http://en.wikipedia.org/wiki/Common_Gateway_Interface#Alternatives
On Client Side:
Good News & Bad News:
You can use PNaCl (Portable Native Client) in chrome. It will be turned on by default.
BUT the first public release is expected in late 2013.Look for PNaCl
You can't do much on the client side - there's no way you can expect the client to have these libraries, and no safe way to download and run them.
The simplest way is to write your server side any way you want, and access them through a web interface. Many languages customarily used for server side scripting can access native C libraries, or you can even write ordinary C applications and run them as scripting agents.
In the "really exotic" category, it is possible to run what starts as C code in the client
if you embed it in a sufficiently protected environment. For example, see the description
of how sqlite (a C database application) was made into a 100% pure java application by
embedding a mips simulator written in java.
http://blog.benad.me/2008/1/22/nestedvm-compile-almost-anything-to-java.html
Looked at Wt yet? Its pretty neat.
Also you have options to code in cgi(ugly).
Although not C, its written in C++. If you can ignore that part: Wt at your service
For doing it client-side, you can use Emscripten. However, this will most probably require some refactoring of your existing code to fit JavaScript's asynchronous main loop requirement.
Note that Emscripten isn't a proof of concept or something like that. It is very powerful and already used to port complex code to the web. You can take a look at the demos (listed in the above URL) to see what can be done with it.
It sounds like you're best off to represent your legacy C library methods as a kind of (WEB) service at the server side. A raw CGI application seems to be a pretty low level point for this approach, but is generally right.
There are C/C++ frameworks available to create webservice servers, and client side libraries that support webservice access and data representation. For the server side you could use gSoap for example.
Another possibility would be to use the webserver of your choice to transmit ordinary files and use a custom webserver (which wouldn't need to support the full HTTP spec) wired up to your C code to communicate with client-side Javascript.
Two minimal webservers you could use as base are libuv-webserver and nweb.
I'm looking for a jabber server library in C++.
I tried glooxd but it's tough to compile, buggy and no activity since more than a year now.
What I'm trying to do, is to be able to build a process that accept xmpp stream, implement it own way to authentify and build custom rosters.
Check out Swiften, a relatively new addition to the XMPP scene. It's primarily used in the client Swift, but also by Spectrum 2, which can act as a server to clients.
In the Swift git repo, there's also a tool called Slimber, that acts as a client in serverless messaging mode, and then presents that as a normal client interface. The server parts of Spectrum 2 and Slimber may be useful for you to study.
Check out the libxmpp project on Sourceforge. I don't know much about it. However, a number of years ago, I wrote a C++ layer on top of the loudmouth library. It's not hard to wrap the C library constructs in thin C++ classes.
Libxmpp: http://sourceforge.net/projects/xmpp/
Loudmouth: https://launchpad.net/loudmouth
Here's my question.
Right now I have a Linux server application (written using C++ - gcc) that communicates with a Windows C++ client application (Visual Studio 9, Qt 4.5.)
What is the very easiest way to add SSL support to both sides in order to secure the communication, without completely gutting the existing protocol?
It's a VOIP application that uses a combination of UDP and TCP to initially set up the connection and do port tunneling stuff, and then uses UDP for the streaming data.
I've had lots of problems in the past with creating the security certificates from scratch that were necessary to get this stuff working.
Existing working example code would be ideal.
Thank you!
SSL is very complex, so you're going to want to use a library.
There are several options, such as Keyczar, Botan, cryptlib, etc. Each and every one of those libraries (or the libraries suggested by others, such as Boost.Asio or OpenSSL) will have sample code for this.
Answering your second question (how to integrate a library into existing code without causing too much pain): it's going to depend on your current code. If you already have simple functions that call the Winsock or socket methods to send/receive ints, strings, etc. then you just need to rewrite the guts of those functions. And, of course, change the code that sets up the socket to begin with.
On the other hand, if you're calling the Winsock/socket functions directly then you'll probably want to write functions that have similar semantics but send the data encrypted, and replace your Winsock calls with those functions.
However, you may want to consider switching to something like Google Protocol Buffers or Apache Thrift (a.k.a. Facebook Thrift). Google's Protocol Buffers documentation says, "Prior to protocol buffers, there was a format for requests and responses that used hand marshalling/unmarshalling of requests and responses, and that supported a number of versions of the protocol. This resulted in some very ugly code. ..."
You're currently in the hand marshalling/unmarshalling phase. It can work, and in fact a project I work on does use this method. But it is a lot nicer to leave that to a library; especially a library that has already given some thought to updating the software in the future.
If you go this route you'll set up your network connections with an SSL library, and then you'll push your Thrift/Protocol Buffer data over those connections. That's it. It does involve extensive refactoring, but you'll end up with less code to maintain. When we introduced Protocol Buffers into the codebase of that project I mentioned, we were able to get rid of about 300 lines of marshalling/demarshalling code.
I recommend to use GnuTLS on both the client and the server side, only for the TCP connection. Forget about the UDP data for now. The GnuTLS documentation has example code for writing both clients and servers. Please understand that at least the server side (typically the TCP responder) needs to have a certificate; the client side can work with anonymous identification (although there is even an example without server certificate, using only DH key exchange - which would allow man-in-the-middle attacks).
In general, it is likely that you will have to understand the principles of SSL, no matter what library you use. Library alternatives are OpenSSL (both Unix and Windows), and SChannel (only Windows).
Have you tried the SSL support in Boost.Asio or ACE? Both use OpenSSL under-the-hood, and provide similar abstractions for TCP, UDP and SSL. Sample code is available in both the Boost.Asio and ACE distributions.
One thing you may need to keep in mind is that SSL is record-oriented instead of the stream-oriented (both TCP and UDP). This may affect how you multiplex events since you must, for example, read the full SSL record before you can call a read operation complete.
To help handle this with no changes to the application yo may want to look at the stunnel project (http://www.stunnel.org/). I don't think that it will handle the UDP for you though.
The yaSSL and CyaSSL embedded SSL/TLS libraries have worked well for me in the past. Being targeted at embedded systems, they are optimized for both speed and size. yaSSL is written in C++ and CyaSSL is written in C. In comparison, CyaSSL can be up to 20 times smaller than OpenSSL.
Both support the most current industry standards (up to TLS 1.2), offer some cool features such as stream ciphers, and are dual licensed under the GPLv2 and a commercial license (if you need commercial support).
They have an SSL tutorial which touches on adding CyaSSL into your pre-existing code as well: http://www.yassl.com/yaSSL/Docs-cyassl-manual-11-ssl-tutorial.html
Product Page: http://yassl.com/yaSSL/Products.html
Regards,
Chris