Network programming using C++ - c++

How can we do network programming in C++ similar to Remoting in .NET? Please help with any tutorials.
It would be fine if I know how to enable two computers to communicate in the form of sending and receiving messages using C++/C#.
Thanks,
Rakesh.

For windows, you can check out this.
You could refer Beej's guide for Unix flavors.

C++ does not have any native networking libraries, so if you don't want to use OS specific calls, you are going to need to use a portability layer.
Two that come to mind are Boost ASIO and ACE.

You may want to have a look at the Poco C++ libraries. Especially the Net module.

For a pure C++ solution (as your first sentence suggests) that's also really simple to use, checkout RCF.
If you want to communicate between C# and C++ programs (as your second sentence suggests) you'll have to look elsewhere, sorry.

Check out our C++ Remoting framework. There's also a screencast showing how to use it.
This is probably the closest that you'll get to .NET Remoting in C++.

Related

Cross Platform C++ Networking (without big library)

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

Are there any RIA Frameworks which allow me to use C++?

I have written an simple applications in C++, and I need to connect with any RIA just for viewing the process ... is there is any good RIA based on C++
Qt is a good, popular cross-platform GUI library for C++.
I don't know whether it matches your definition of "RIA", though.
Silverlight is the nearest framework for you. You may find this Stackoverflow question interesting.
Update
After seeing your comment, I'd recommend you using ISAPI or CGI programming in C or C++
Update 2
After figuring that you need to execute C++ code from browsers, The answer is ActiveX. But portability is an issue, rather.
Generally speaking, this is difficult to do. Clients don't trust running arbitrary C++ code from the internet, because people don't want every website under the sun to be able to install malware, and generally hijack the entire machine, every time they visit a web site. In the general case, therefore, what you want is not really possible.
If you're willing to require the user to answer a ton of prompts, and are okay restricting your application to Internet Explorer on Windows, you could familiarize yourself with COM and write an ActiveX control.
I would strongly advise against doing so, however.
Have you looked at Qt? It comes with Webkit built-in. It is also more portable than other RIA implementations. BTW, most RIA implementations run on language virtual machines that are in turn implemented in C or C++ :-)

Beginner: Sending data over sockets

Can anyone find an example of a simple server/client thing? I'm willing to use any C++ library or even Winsocks it self. I've Googled around but want some opinion on a good article for beginners/sites.
If you're willing to use a C++ library, I heartily recommend Qt. It gives you an easy way to communicate with sockets, and much more. In particular see the QtNetwork module - a few of its relevant classes for your cause: QTcpSocket, QTcpServer, QUdpSocket.
see
http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html
If you are looking for a C++ networking library, I suggest Asio, which is now part of Boost. Start with the Tutorial. Also have a look at the examples.
JFGI
http://www.adp-gmbh.ch/win/misc/sockets.html
http://tldp.org/LDP/LG/issue74/tougher.html
I like ACE. It is a pretty large library but there are some core classes that are really easy to use for beginning network programming.
Here's a really good book for ACE too.
Ace Programming Guide

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.

How to use the C++ Sockets Library

I'd like to do some network socket programming in C++ and have found the C++ Sockets library.
First, is this a good way to go in C++? Normally in C, I'd use some of the stuff beej describes in his tutorial.
Second, how do I compile the examples given on the site? I can't figure it out from their installation/configuration guide. So I download the tar.gz to my Linux box, then what?
To have a specific example, how do I compile and run the DisplaySocket example?
Thanks.
EDIT: Thank you for the quick answers. A comment though. I'm not really looking into "understanding" network programming as I think I do that well enough already. I want to know if there's anything in particular to take advantage of in C++, and - if "the C++ Sockets Library" is a good choice - how to use it.
That's not "the" C++ sockets library, it's "a" C++ sockets library. Boost.asio has another (http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio.html).
(Community Wiki since I can't actually help you with your question - I've never compiled the code you ask about, so I don't know at what point you might have tripped over a problem).
Network programming would be better understood by using basic socket api (BSD or WinSock) rather than a socket library which hides most of the intricacies about sockets and their behaviour.
I would second the vote for boost::asio since it encapsulates the inversion of control model that is the current, preferred model, and appears to be standard-bound. To learn what the documentation doesn't tell you, google Douglas Schmidt and his books.
I like to use the ACE networking library when I write networking code in C++. I think it does a nice job abstracting some of the intricate details away that make network coding painful but doesn't do it to the point where it hides what is going on under the hood. It also has facilities for threading and messaging which usually are needed for any project.