Call the Create member function after constructing a socket object to create the Windows socket and attach it.
BOOL Create( UINT nSocketPort = 0, int nSocketType = SOCK_STREAM, LPCTSTR lpszSocketAddress = NULL );
A particular port to be used with the socket, or 0 if you want MFC to select a port.
SOCK_STREAM or SOCK_DGRAM.
A pointer to a string containing the network address of the connected socket, a dotted number such as "220.127.116.11". Passing the NULL string for this parameter indicates the CSocket instance should listen for client activity on all network interfaces.
Create then calls Bind to bind the socket to the specified address. The following socket types are supported:
SOCK_STREAM Provides sequenced, reliable, two-way, connection-based byte streams. Uses Transmission Control Protocol (TCP) for the Internet address family.
SOCK_DGRAM Supports datagrams, which are connectionless, unreliable buffers of a fixed (typically small) maximum length. Uses User Datagram Protocol (UDP) for the Internet address family. To use this option, you must not use the socket with a CArchive object.
The Accept member function takes a reference to a new, empty CSocket object as its parameter. You must construct this object before you call Accept. Keep in mind that if this socket object goes out of scope, the connection closes. Do not call Create for this new socket object.