Windows Sockets in MFC

HomeOverviewHow Do ISample

MFC supplies two models for writing network communications programs with Windows Sockets, embodied in two MFC classes. This article describes these models and further details MFC sockets support. A “socket” is an endpoint of communication — an object through which your application communicates with other Windows Sockets applications across a network.

This article describes:

For background information on Windows Sockets, including a detailed explanation of the socket concept, see the article Windows Sockets: Background.

Sockets Programming Models

The two MFC Windows Sockets programming models are supported by the following classes:

Creating and using CSocket and CAsyncSocket objects is described in the articles Windows Sockets: Using Sockets with Archives and Windows Sockets: Using Class CAsyncSocket.

MFC Socket Samples and Windows Sockets DLLs

Visual C++ supplies the CHATTER and CHATSRVR sample applications to illustrate the client/server model, which is the most common model. CHATTER is the client; CHATSRVR is the server. These samples make good templates for writing your own clients and servers. You can access the source code for the MFC Advanced Concepts samples CHATTER and CHATSRVR.

The Microsoft Windows NT operating system supplies the Windows Sockets dynamic link libraries (DLLs). Visual C++ supplies the appropriate header files and libraries and the Windows Sockets specification. The specification is available in the Win32 SDK.

Note   Under Windows NT, Windows Sockets support for 16-bit applications is based on WINSOCK.DLL. For 32-bit applications, the support is in WSOCK32.DLL. The APIs provided are identical except that the 32-bit versions have parameters widened to 32 bits. Under Win32, thread safety is supplied.

ClassWizard does not support creating classes derived from the MFC Windows Sockets classes.

Windows Sockets Articles

For detailed information about Windows Sockets and their implementation in MFC, see the following articles: