I wrote a very simple client app and server app in Win32. Now I want to write a more robust chat program. Instead of just using socket(), bind(), etc. for TCP/IP and CreateThread() for multithreading, I''m exploring the realm of MFC.
My question is: what exactly are CSocketFile and CArchive? Are these the data types that Winsock uses to make the packets it sends over TCP/IP?
With Win32 I was simply sending NULL terminated character strings, but now it seems I''m working with actual files. I assume my previous code was also transmitting files because you can just transfer a memory buffer over TCP/IP right (sorry if that sound dumb)?
I''m confused right now. Can someone please explain the minimal code needed to send a packet from a client to a server and what each instruction is doing? Or, is there a simple tutorial on the Internet that can answer my questions?
Are books a better way to go about learning TCP/IP? I only need to know some simple stuff for what I’m working on. Give me a foundation for basic communication and a good explanation on how it works, I can be creative about the rest.
Thanks for your time.
P.S. I''m just getting started on this so please excuse this message if my questions are stupid. Perhaps I should have done more research on my own before I bothered you. However, even though MFC does seem to be making things progress faster, it generates a lot of crazy code and I''m barely treading water.
CSocketFile and CArchive are MFC wrappers for turning a file or someother buffer into a byte stream. The CSocket class that MFC uses translate the CArchive or CSocketFile into a char buffer and blasts it out on the socket.
Winsock has no clue what the heck a CArchive or CSocketFile is. It only sees a char buffer.
IMO, the MFC wrapper for Winsock is pretty ugly. You''re better off just using the Win32 API calls.
Anyway, are you looking for the minimal code for sending a packet in MFC code or Straight Winsock calls?
Thanks SiCrane. I was right, a little more research on my own did make a big difference. A few moments after I posted, I learned that CArchieve just serializes the data transmissions from CSocketFile. Alternately, you could transmit the CSocketFile data yourself with member function calls. Anyway, I still obviously have much more to learn.
Can you please send me both SiCrane so I can compare for myself? I''m using MFC for other stuff so I might as well take advantage of it since it''s already there. I know Winsock 2 is more complicated than Winsock 1.1 and I thought MFC would help simplify things. I usually hate wrappers because I like to know exactly how everything works, but I need to get moving on this project.
Example code for all sorts of Winsock coding can be found at www.sockaddr.com. These are the sample codes from Napper''s book "Winsock 2.0." If you want to do any programming at all in Winsock, I highly recommend buying this book. Chapter 6 in covers MFC sockets. Chapter 2''s Datagram client/server is about as basic as you can get with pure Winsock calls.