Cross Platform C ++ Networking (no big library)

I think it's best if I explain the situation so that it doesn't seem like a too cryptic question. I want to post a starter code for a project that I want some of my students to work on. The project involves scrubbing through some web pages and as such I want to provide them with a URLStream class that will load the html of the input url and return it as a string for them.

The problem is that I cannot find a particularly nice way to communicate with the network in a way that is cross-platform (students have Mac / windows / linux). I know libraries like Boost asio and libCurl, but the problem with using them is that I cannot ensure that all my students load them. So my question is twofold:

  • Is there a good way to provide them with this network code?
  • If the library is the only way to do this, is there a way to attach the library to the starter project so that students don't download it? I know this might be a stupid question, but I cannot figure out if this is possible.
+3


source to share


3 answers


The Berkeley Sockets API is the most common low-level socket API. It is supported on all POSIX platforms, which means Linux and MacOS will have it.

Even Windows has this, but with a slight twist, since sockets are not descriptors like they are on POSIX systems.



Using sockets will directly result in boiler room code, but it can certainly be used to create a simple HTTP client that only supports simple requests GET

.

There are many tutorials and links out there for using sockets. The Beej Guide to Network Programming seems to be a popular tutorial that should have notes on the settings required for Windows.

+1


source


Boost.Asio

really doesn't fit your needs as it involves a huge Boost and making at least some of its non-headers. You can still consider a Asio

lib
that can be used without Boost and only with a header, so you have less trouble for your students. Since it is arguably the most popular and modern networked C ++ lib, this exercise can provide a rewarding experience for students. The Asio examples also have a simple HTTP client .



As a side note, are you C ++ related for this assignment? This would be much easier in Python or similar languages, which would provide networking out of the box.

+1


source


C ++ cross platform 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 was recently adopted by Boost.

I copied this from the info window in Synaptic. If you are using Linux, install the library (and its documentation) this way:

sudo apt-get install libasio-dev libasio-doc

0


source







All Articles