CSocketFile

A CSocketFile object is a CFile object used for sending and receiving data across a network via Windows Sockets. You can attach the CSocketFile object to a CSocket object for this purpose. You also can — and usually do — attach the CSocketFile object to a CArchive object to simplify sending and receiving data using MFC serialization.

To serialize (send) data, you insert it into the archive, which calls CSocketFile member functions to write data to the CSocket object. To deserialize (receive) data, you extract from the archive. This causes the archive to call CSocketFile member functions to read data from the CSocket object.

Tip Besides using CSocketFile as described here, you can use it as a stand-alone file object, just as you can with CFile, its base class. You can also use CSocketFile with any archive-based MFC serialization functions. Because CSocketFile does not support all of CFile’s functionality, some default MFC serialize functions are not compatible with CSocketFile. This is particularly true of the CEditView class. You should not try to serialize CEditView data through a CArchive object attached to a CSocketFile object using CEditView::SerializeRaw; use CEditView::Serialize instead. The SerializeRaw function expects the file object to have functions, such as Seek, that CSocketFile does not have.

For more information, see Windows Sockets in MFC, Windows Sockets: Using Sockets with Archives, and related articles in Visual C++ Programmer’s Guide, as well as Overview of Windows Sockets 2 and Windows Sockets Programming Considerations in the Win32 SDK documentation.

#include <afxsock.h>

Class MembersBase ClassHierarchy Chart

See Also   CAsyncSocket, CSocket