Cross Platform C++ Networking (without big library) - c++

I think it is better if I explain the situation so this doesn't seem too arcane a question. I want to release some starter code for a project I want some of my students to work on. The project involves scraping through some internet webpages and as such, I want to provide them with a URLStream class that will download the html of an input url and return it as a string to them.
The issue is that I can't seem to find a particularly nice way to deal with networking in a way that will be cross platform (the students have mac/windows/linux machines). I know of libraries like Boost asio and libCurl, but the issue with using these is that I can't enforce all my students download them. So my question is twofold:
Is there any nice way to provide them this cross platform networking code?
If a library is the only way to do this, is there any way to attach the library to the starter project so that students don't have to download it? I know this might be a stupid question but I can't seem to find out if this is possible.

Boost.Asio is really not suitable for your needs as it involves huge Boost and building at least some of its non-header-only libs. You can still consider Asio lib that can be used w/o Boost and is header-only lib, so much less hassle for you and your students. As it's probably the most popular and modern networking C++ lib this exercise can provide some useful experience to the students. Asio examples also have a simple HTTP client.
As a side note, are you bound to C++ for this assignment? It would be much simpler in Python or similar languages that provide networking out of the box.

The Berkeley sockets API is the most common low-level socket API. It is supported on all POSIX platforms which means both Linux and macOS will have it.
Even Windows have it, but with a slight twist since sockets aren't descriptors like they are on POSIX systems.
Using sockets directly will lead to more boiler-plate code, but it is definitely possible to use it to make a simple HTTP client that supports only simple GET requests.
There are many tutorials and references on using sockets. Beej's Guide to Network Programming seems to be a popular tutorial, which should have notes about the tweaks needed for Windows.

cross-platform C++ library for network programming
asio is a cross-platform C++ library for network programming that provides
developers with a consistent asynchronous I/O model using a modern C++
approach. It has recently been accepted into Boost.
I copied that from the info window in Synaptic. If you're using Linux, install the library (and its documentation) thus:
sudo apt-get install libasio-dev libasio-doc

Related

How could I create an AVAHI client & server using C++?

I'm coding a C++ library that, among other things, needs to:
Search for a specific service in a network using AVAHI
Publish itself as a service using AVAHI
I've been searching for existent options. I've found that the creators of POCO C++ offer a DNS-SD library integrated with POCO C++. That would work, because I'm actually using POCO C++, but it's a commercial library, and I can't afford it.
Apart from that, avahi-daemon offers a client interface that allows browsing services and publishing new ones. It also sounds good, but I need my code to be portable, and work in major Linux distributions, Mac OS X and Windows. AFAIK, this solution would only cover Linux (where avahi-daemon is available).
I guess as partial solution, I could just send a properly formatted message via socket and process the raw response. That way, I could search for services published using AVAHI. But I think that's ugly and unmaintainable.
So, is there any good-enough solution for this without buying a software? I know this can be done using Python, but I need to do it in C++.
Many thanks in advance
There is an Open Source library (released under the LGPL) available over at http://avahi.org/. It exposes a C interface that can be very easily used in a c++ program.
There are also prebuilt binary version available for all major distros.

Non GPL C/C++ XMPP client library for embedded Linux

Does anyone know of a good non GPL C/C++ XMPP client library that works for embedded Linux in ARM machines?
I've checked out txmpp but the last update seems to be 2 years ago.
qxmpp seems to require Qt, which I'm not sure is supported in embedded Linux. Also, AFAIK Qt is for GUI, so I'm not sure why a library requires it.
I also checked out gloox, but it's GPL and seems to be over a year old too.
Non GPL C/C++ XMPP client library for embedded Linux
libstrophe - dual-licensed under Mit/GPLv3. However, I'm not sure if it will compile on ARM, although it should be fairly portable.
so I'm not sure why a library requires it.
Because Qt provides XML parser and signal/slot framework. XMPP requires XML parser, and signal/slot framework makes your life easier. If you try implementing entire XMPP with all extensions in OOP fashion, you'll need something similar to Qt. If you simply need to send a command or two, then bare bones solution will do.
libstrophe is bare bones. You won't get dozens of wrappers representing different xmpp concepts (and legion of extensions), but you'll be able to send commands you need/want. You'll have to read XMPP specifications, of course.
Advice: when it comes to C++, there aren't many good xmpp libraries available.
I think it happens for following reasons (personal opinion):
Too many protocol extensions
It is easy to get distracted while making xmpp libraries. Xmpp contains fairly large number of possible errors, and OOP-minded programmist will be extremely tempted to make a class for everything, which doesn't work well in this scenario and requires something like Qt 4 to make it work properly.
XMPP requires XML parser.
As a result, it might make sense to try python - IF your embedded platform can handle it. For python, there's xmpppy. Although I strongly dislike python, I think it'll be easier to work with XMPP in python using xmpppy than in C++ using libstrophe. This is because xmpp requires plenty of key-value pair lists, and python represents such constructs in more "natural" way, using dictionaries.
I had the same problem so i rolled my own. Released under BOOST license; http://deusexmachinae.se/dxmpp
It only supports core functionality + proper authentication (including TLS and SCRAM-SHA-1).

Scalable server framework in C++

I am looking to write a server application in C++ that is meant to handle tens of thousands of clients simultaneously. It should run under Windows and Linux. I have been looking around for frameworks and libraries and have come across Boost Asio, which seems like a highly mature and widely used alternative. I just have trouble wrapping my head around strands/thread pools, mainly because of the millions of templates. My background is mainly in C, so am not really used to the template mess that Boost in general seems to be full of. I tried to find someone to develop a relatively thin wrapper around Boost Asio that would take care of the threading/synchronization aspect using strands, bind and the like, but have been unable to find someone yet who can do it within my budget (2 or 300 US dollars).
Can any of you recommend any other libraries that scale as well as Boost Asio (e.g. with IOCP on Windows and epoll on Linux etc), or a source where I might find skilled Boost developers looking for smaller freelance jobs?
Thanks very much in advance for any help.
Kind regards,
Philip Bennefall
Best 4 choices i know
I really like zeromq.. but libuv seems interesting.. (libev and libevent are very nice too)
zeromq
libevent (as said)
libev
libuv (Its purpose is to abstract
IOCP on windows and libev on Unix systems and it is node.js network layer)
ACE is the framework you are looking for. Even boost Asio is just an implementation of Proactor pattern, which was introduced by Douglas C. Schmidt. He is best known as the author of POSA Vol.2 and the creator of ACE framework.
The Boost.Asio library offers side-by-side support for synchronous
and asynchronous operations ... based on the Proactor design pattern
[POSA2].
Although it is a cross-platform C++ network framework and uses template,
just simple template is used. (or not at all)
My background is mainly in C, too, and I don't like Boost's massive template-programming style. However, ACE wasn't like that.
Try libevent on for size. Its whole raison d'etre is to address the C10K problem. I'd say it's probably more lightweight than boost.
Try Pulsar Server Framework. Main benefit is it is built over libuv network library (used by node.js) that uses asynchronous I/O based on event loops.
It’s perfectly scalable. You can just go adding servers as your user base increases.
It is designed to work with server farm.
Highly configurable and easy to use
Currently it has been built for Windows x64 server.

Whats the most basic way to go online in c++?

What is the most basic way to go to a webpage and download its contents? the webpage i wish to get only has text, most of which is in tables.
is there a std library that does it (like urllib in python)?
There's no official C++ network library, no. There are many different APIs available, though. Which is best for you would depend on what platform(s) you were targeting and what framework(s) you might already be using.
That said, cpp-netlib is a platform-neutral API that follows C++ idioms nicely. I've used it and it works.
A large number of tasks that are not covered by the C++ standard library can be done using boost, the collection of peer-reviewed portable libraries, which are used by pretty much every C++ project today. For networking, we use boost.asio.
Their tutorials include HTTP clients: http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/http/client/sync_client.cpp and http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/http/client/async_client.cpp
However, although this is highly portable and may end up becoming part of the C++ standard library in future, it is a bit too low-level for your task. libCURL is the today's default library for HTTP downloads.

Recommend crossplatform C++ UI and networking libraries

Things to take into consideration:
- easy to use
- fast
- use underlying OS as much as feasable (like wxWidgets for UI)
Ones I am leaning towards are wxWidgets for UI and Boost for networking - how do they compare to others?
I hear good things about qt for GUI
Qt is a cross-platform application and
UI framework. Using Qt, you can write
web-enabled applications once and
deploy them across desktop, mobile and
embedded operating systems without
rewriting the source code
I've had good look with wxWidgets on the front end and boost::asio on the network end.
wxWidgets does have network classes built in, but you hit the wall quickly on them, and there's one or two big limitations. If you want to stay in the wx world, there's a package called wxCurl which is a fine package (I used it in the early days) that wraps libCurl with some wxWidgets idomatic C++.
In a previous project of mine (a network/file transfer heavy project) we ended up going with boost::asio, which had the advantage of not being all that hard of an API, easier-seeming to set up that libCRUL (although that may have gotten better, that was been several years now), and gives us a very generic networking core (boost can compile anywhere, even command line apps)
For GUI I would strongly recommend using Qt. It is very powerful GUI framework that requires writing very few lines of code. It has very nice and easy to use model of signals and slots.
wxWidgets IMHO too modeled after MFC which has very bad model.
Networking: I would suggest go for Boost.Asio very powerful and nice. However if you
want to integrate networking to GUI main loop you may try to use Qt classes for that, however I have no experience with them.
I've used XVT historically, which has been used commercially by thousands of companies.
Both Qt or wxWidgets can do networking even if it's not their first goal.
For more network centric libraries, apart from boost::asio, you can check ACE (Adaptative Communication
Environment ) or POCO
Comparisons between these libraries have already been discussed on stackoverflow.
boost::asio seems to be very well written, and has a very clean API -- I am still trying to learn how well it is for shared-nothing multithreaded TCP/IP.
Your other choices might be Poco, or ACE. Poco's socket abstraction is quite naive --i.e., it only allows the Poco way of doing things. I've never heard anything good about ACE.
edit: Hmm, I'm re-examining ACE and its making more sense to me now (after having written a few networking apps) -- it might be suitable for my needs compared to ASIO. However, it is more than likely overkill for you. If my peers find out about this, I will be shunned till the end of time.
We have had good success using wxWidgets with boost::asio, both recommended for desktop-server development.
For GUI, I can recommend QT
For Networking ACE (Adaptive Communication Environment) or boost::asio.