Is C++ better than C for winsock programming?

Started by
2 comments, last by nPawn 24 years, 2 months ago
for a game? It seems that using inheritance and maybe templates would be a great way to make a generic networking system, yet all the examples i see for writing winsock programs are in C++. Does anyone know where some good examples of a basic C++ network engines are, or perhaps have some tips on the best way to design a basic network object? Or is it best to stick with straight C for network programming?
Advertisement
One reason that you may only see C code examples for winsock, is that the winsock API is already fairly object oriented. To create a socket you call a constructor specifying it''s protocol, and boom you get a handle to a socket and you start calling functions on it. The functions you call are the same no matter what protocol you specified. That being said, it might be easier if you encapsulated the functions yourself in C++, but it would basically only aid your understanding of the code. I personally use C style socket calls exclusively.
Check out the Windows version of mAngband. It is open source, and uses UDP.
I would suggest writting your own class to wrap up the winsock code. This allows two things. One: You encapsulate the down-and-dirty code. Two: You can reuse the objects. I have a set of classes that I have used for the past couple projects, they are much more robust and have less overhead (read smaller feature-set) than the CSocket class offered in MFC. If you want I can send you the source and some examples of how to use them.
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous

This topic is closed to new replies.

Advertisement