Socket API or library for C++?

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 .h file(s) of the library, adding extern "C" in front of all function and global variable declarations.

To find libraries, go to http://freshmeat.net/ , and search for C++ socket or C socket. Here is what I’ve found for C++ 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 socket on freshmeat, you may find a C library which suits better than any C++ library.

Leave a Comment