I recently have been getting more into C++. I have done some (very minimal) socket programming with C, but have been interested in doing some work with C++. I have only been able to find reference/tutorials on C based socket implementations. Is there a reason for this? I know, or believe I know that you can use the C socket libraries for C++, but am not sure.
Is there a C++ socket library that is used more often then others? This isn’t a subjective question, I am actually looking to find out what the Socket API’s/libraries are for C++.
I am fairly new at socket programming and C++, so please no answers that will throw me for a loop.
Thanks
Here I’m attempting to answer some of your specific, factual questions to which I have something to contribute.
Yes, you can use any C socket library in C++. If it doesn’t work out-of-the-box because the linker reports an undefined reference for the library functions you want to use, then can fix it by editing the
.hfile(s) of the library, addingextern "C"in front of all function and global variable declarations.To find libraries, go to http://freshmeat.net/ , and search for
C++ socketorC socket. Here is what I’ve found forC++ socket:As Raphael has mentioned in his answer, you might find the socket part of the Qt library useful. See QTCpSocket for reference, and the fortune client for example code.
Also Boost.Asio has popped to my mind, but it might have too much abstraction and low-level details exposed for you.
Do your search for
C socketon freshmeat, you may find a C library which suits better than any C++ library.