Is C++ better than C for winsock programming?
3 replies to this topic
Members - Reputation: 110
Posted 27 January 2000 - 06:01 AM
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?
Moderators - Reputation: 11291
Posted 28 January 2000 - 04:25 AM
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.
Members - Reputation: 122
Posted 31 January 2000 - 03:24 PM
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.