I'm learning C++ and so I've decided to begin coding a IRC-Client.
I basically want it to be consolebased, and I've looked in to libraries such as ncurses, but I don't really know whether or not this would be the best approach.
I imagine the UI being divided into one part where whatever messages are written appear, and one part where the users input goes. Ncurses seemed to be able to do this, but now I've discovered another issue.
Because I want the message-part to be event driven (whenever somebody sends a message, this should appear in the message-part) the message-part of the UI should run independently from the input-part. Also, sockets would have to be non-blocking as well.
I've looked around on the internet and haven't found any good tutorials on this, as most are either really, really old, poorly written or simply just to long.
Anyways, my questions are, how would this be done using the ncurses and socket libraries? Are their any good C++ wrappers (one thing I've learned from reading ncurses tutorials is that OOP is really wonderful...)?
You'll probably need to use a few threads to do that, so I'd take a look at pthreads.
However, you shouldn't be afraid of long tutorials, because what you're trying to achieve is not so simple, specially if C++ is the first computer language you learn.
Using ncurses for the interface sounds like a good idea. You can do a single-threaded select-based network and terminal client -- check out Beej's guide. Alternatively, Boost.asio, single-or-multithreaded, should be a solid choice, too.
So I need to introduce myself to sockets and general network programming. I consider myself fluent in C++, but I basically can build stuff with the basics of C++ (think having only a basic set of legos)
Now I really need to venture forth and expand my lego set to different pieces (pardon the lego metaphor) But socket programming/network is my next target. So I thought a simple program to write would be a file sending program.
Basically a program that you type in the IP of your friend, (he has the program too) and it asks "Would you like to receive fileXXX.yyy" If he says yes, then it proceeds to send the file.
I know i'd need to know about sockets, but what else would I need to know about? Should this be a simple program to accomplish? Any recommended tutorials I read before I dive head first?
Any additional info is helpful. Thanks. And NO this is not for school, it's just kinda something I wanna learn.
C++ preferred language.
You should get yourself the boost libraries.
There is no standard socket API for C++ but boost provides one in their ASIO library that will work on multiple platforms (as is the case with all boost libraries).
beej has a good guide for unix socket programming:
http://beej.us/guide/bgnet/
You can use the same code on a windows platform if you include the winsock library and an additional startup call
The Boost.Asio library mentioned in CashCow's answer is a fantastic cross-platform and easy to use library. Don't let the asynchronous name scare you, it can be a bit daunting at times but the documentation is straightforward and easy to understand.
The boost-asio tag is also fairly active on stack overflow.
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
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++.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I have been working with the Boost C++ Libraries for quite some time. I absolutely love the Boost Asio C++ library for network programming. However I was introduced to two other libraries: POCO and Adaptive Communication Environment (ACE) framework. I would like to know the good and bad of each.
As rdbound said, Boost has a "near STL" status. So if you don't need another library, stick to Boost. However, I use POCO because it has some advantages for my situation. The good things about POCO IMO:
Better thread library, especially a Active Method implementation. I also like the fact that you can set the thread priority.
More comprehensive network library than boost::asio. However boost::asio is also a very good library.
Includes functionality that is not in Boost, like XML and database interface to name a few.
It is more integrated as one library than Boost.
It has clean, modern and understandable C++ code. I find it far easier to understand than most of the Boost libraries (but I am not a template programming expert :)).
It can be used on a lot of platforms.
Some disadvantages of POCO are:
It has limited documentation. This somewhat offset by the fact that the source is easy to understand.
It has a far smaller community and user base than, say, Boost. So if you put a question on Stack Overflow for example, your chances of getting an answer are less than for Boost
It remains to be seen how well it will be integrated with the new C++ standard. You know for sure that it will not be a problem for Boost.
I never used ACE, so I can't really comment on it. From what I've heard, people find POCO more modern and easier to use than ACE.
Some answers to the comments by Rahul:
I don't know about versatile and advanced. The POCO thread library provides some functionality that is not in Boost: ActiveMethod and Activity, and ThreadPool. IMO POCO threads are also easier to use and understand, but this is a subjective matter.
POCO network library also provides support for higher level protocols like HTTP and SSL (possibly also in boost::asio, but I am not sure?).
Fair enough.
Integrated library has the advantage of having consistent coding, documentation and general "look and feel".
Being cross-platform is an important feature of POCO, this is not an advantage in relation to Boost.
Again, you should probably only consider POCO if it provides some functionality you need and that is not in Boost.
I've used all three so here's my $0.02.
I really want to vote for Doug Schmidt and respect all the work he's done, but to be honest I find ACE mildly buggy and hard to use. I think that library needs a reboot. It's hard to say this, but I'd shy away from ACE for now unless there is a compelling reason to use TAO, or you need a single code base to run C++ on both Unix variants and Windows. TAO is fabulous for a number of difficult problems, but the learning curve is intense, and there's a reason CORBA has a number of critics. I guess just do your homework before making a decision to use either.
If you are coding in C++, boost is in my mind a no-brainer. I use a number of the low level libraries and find them essential. A quick grep of my code reveals shared_ptr, program_options, regex, bind, serialization, foreach, property_tree, filesystem, tokenizer, various iterator extensions, alogrithm, and mem_fn. These are mostly low-level functionality that really ought to be in the compiler. Some boost libraries are very generic; it can be work to get them to do what you want, but it's worthwhile.
Poco is a collection of utility classes that provide functionality for some very concrete common tasks. I find the libraries are well-written and intuitive. I don't have to spend much time studying documentation or writing silly test programs. I'm currently using Logger, XML, Zip, and Net/SMTP. I started using Poco when libxml2 irritated me for the last time. There are other classes I could use but haven't tried, e.g. Data::MySQL (I'm happy with mysql++) and Net::HTTP (I'm happy with libCURL). I'll try out the rest of Poco eventually, but that's not a priority at this point.
Many POCO users report using it alongside Boost, so it is obvious that there are incentives for people in both projects. Boost is a collection of high-quality libraries. But it is not a framework. As for ACE, I have used it in the past and did not like the design. Additionally, its support for ancient non-compliant compilers has shaped the code base in an ugly way.
What really distinguishes POCO is a design that scales and an interface with rich library availability reminiscent of those one gets with Java or C#. At this time, the most acutely lacking thing from POCO is asynchronous IO.
I have used ACE for a very high performance data acquisition application with real time constraints. A single thread handles I/O from over thirty TCP/IC socket connections and a serial port. The code runs on both 32 and 64 bit Linux. A few of the many ACE classes I have used are the ACE_Reactor, ACE_Time_Value, ACE_Svc_Handler, ACE_Message_Queue, ACE_Connector. ACE was a key factor to the success of our project. It does take a significant effort to understand how to use the ACE classes. I have all the books written about ACE. Whenever I have had to extend the functionality our system it typically takes some time to study what to do and then the amount of code required is very small. I have found ACE to very reliable. I also use a little bit of code from Boost. I do not see the same functionality in Boost. I would use either or both libraries.
I recently got a new job and work on a project that uses ACE and TAO. Well, what I can tell is, that ACE and TAO work and fully accomplish their tasks. But the overall organisation and design of the libraries are quite daunting...
For example, the main part of ACE consists of hundreds of classes starting with "ACE_". It seems like they've ignored namespaces for decades.
Additionally, many of ACE's class names don't provide useful information either. Or can you guess what classes like ACE_Dev_Poll_Reactor_Notify or ACE_Proactor_Handle_Timeout_Upcall can be used for?
Additonally, the documentation of ACE is really lacking, so unless you want to learn ACE the hard way (it is really hard without any good documentation..), I would NOT recommend using ACE, unless you really need TAO for CORBA, If you don't need CORBA, go ahead and use some modern libraries..
Boost enjoys a "near STL" status due to the number of people on the C++ standards committee who are also Boost developers. Poco and ACE do not enjoy that benefit, and from my anecdotal experience Boost is more widespread.
However, POCO as a whole is more centered around network-type stuff. I stick to Boost so I can't help you there, but the plus for Boost is its (relatively) widespread use.
The ACE socket libraries are solid. If you are trying to port a standard implementation of sockets you can't go wrong. The ACE code sticks to a rigid development paradigm. The higher level contructs are a little confusing to use. The rigid paradigm causes some anomolies with exception handling. There are or used to be situations where string value pairs being passed into an exception with one of the pair being null causes an exception throw in the exception that will boggle you. The depth of the class layering is tedious when debugging. I have never tried the other libraries so can't make an intelligent comment.
Boost is great, I've only heard good things about POCO (but never used) but I don't like ACE and would avoid it in future. Although you will find fans of ACE you will also find many detractors which you don't tend to get with boost or poco (IME), to me that sends a clear signal that ACE is not the best tool (although it does what it says on the tin).
Out of those I've only ever really used ACE. ACE is a great framework for cross-platform enterprise networking applications. It's extremely versatile and scalable and comes with TAO and JAWS for quick, powerful development of ORB and/or Web based applications.
Getting up to speed with it can be somewhat daunting, but there is a lot of literature on it, and commercial support available.
It's somewhat heavy though, so for smaller-scale apps it may be a bit of an overkill. Reading the summary for POCO it sounds like they're aiming for a system that can be run on embedded systems so I'm assuming it can be used in a much lighter way. I may now give it a whirl :P
I think it is really matter of an opinion, there is hardly a right answer.
In my experience with writing portable Win32/Linux server code (15+ years), I personally find boost/ACE unnecessarily bloated and introduces maintenance hazards (otherwise known as "dll hell") for the little advantage they give.
ACE also seems to be horribly outdated, it is a "c++ library" written by "c programmers" in the 90-s and it really shows in my opinion. It so happens, right now I am re-engineering the project written with Pico, it seems to me it completely follows the ACE idea, but in more contemporary terms, not much better at that.
In any case for high performance, efficient, elegant server communications you might be better off not using any of them.