Socket Programming with C++ and Windows

Status
Not open for further replies.

KornNut

In Runtime
Messages
226
Does any one know of any good tutorials or examples of a network C++ program that runs on Windows and uses Sockets?
 
I'm sure there are some... I've never really used sockets directly though, in windows programming.

I've always used them indirectly through some kind of API (ex. MFC, etc) and now the .NET stuff is all going to be done the same way.

You might look at some of the stuff on CSocket in MSDN though, even though its no longer current. I learned on that stuff, and I know using the actual SOCKET struct isn't too much different, other than you having to handle all the buffer pointers and callback functions yourself.
 
So what exactly does MFC do?

Is it a software patch that does all of the networking for you?

Will it work with C++/.NET/Windows/OpenGL?
 
I used MFC CSocket class in my OpenGL when I was dabbling in multiplayer stuff.

MFC = Microsoft Foundation Classes. Its basically been deprecated by ATL and now by .NET standard libraries. It was just a group of classes that abstracted the dirty work of SOCKET programming. (And everything else related to WinAPI programming in C++)

I don't know how to give a quick description of socket programming, but I can probably give you some basic guidance.

Now, forgive me on the basic syntax since I never do it the 'primitive' way of SOCKET structs, I just crack open my handy library classes book and grab the appropriate class and member funcs, but I digress....

You've basically got a struct called SOCKET where you're passing it in and out of a bunch of library functions, like recv(), send(), accept(), connect(), etc.

Each time you're passing your SOCKET pointer and whatever other structures it calls for.

Usually you're going to also have to create a call back function which takes certain params (look this up) and then pass the address of your function into one of the standard library funcs so that it can 'wake up' your code when data is received.

All the rest of the stuff is just done like file input and output. Once you want to send, or you are alerted to receive, you just read like old style C file I/O. You read or write a buffer, and supply a specific buffer length. You read in this case until some kind of SOCKET_ERROR (like EOF) or write until you run out of data to write.
 
Status
Not open for further replies.
Back
Top Bottom