views:

515

answers:

4

Hi,

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.

+3  A: 

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.

Indeera
Spending more than 5 minutes on the raw socket API is a waste of time. All more would teach you are the little bugs that each implementation has, which any library would make irrelevant. "Network programming" is best learned from a library which modes inversion of control and event handling. See Schmidt's C++ Network Programming books.
keraba
which bugs for example ?
Indeera
See Stevens. Perhaps "undocumented differences between platforms" would be a better description.
keraba
+8  A: 

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).

Steve Jessop
It calls itself the C++ Sockets Library, which is why I changed the question title.
anon
Thank you. I think it's fair to write "the" though when I link to the specific project site.
anderstornvig
OK, I'll blame them for any confusion. In any case, chances are Boost is more widely-used, and might be a better way to go solely on those grounds. Plus you might be able to grab it through your distro, meaning no installation hassles. Just a thought.
Steve Jessop
Thank you. Boost seems to be a good way to go. Also because it has other useful capabilities. And I've managed to install it : ).
anderstornvig
A: 

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.

zooropa
If you're going to give -1, at least tell me why. Please explain why you gave me -1 for this answer. ACE is a C++ networking library that I'm recommending to use. I think this is relevant to the first part of the question that asks if C++ Sockets library is the way to go. I'm saying that ACE is an alternative to the C++ socket library.
zooropa
A: 

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.

keraba