CSocket::Create

BOOL Create( UINT nSocketPort = 0, int nSocketType = SOCK_STREAM, LPCTSTR lpszSocketAddress = NULL );

Return Value

Nonzero if the function is successful; otherwise 0, and a specific error code can be retrieved by calling GetLastError.

Parameters

nSocketPort

A particular port to be used with the socket, or 0 if you want MFC to select a port.

nSocketType

SOCK_STREAM or SOCK_DGRAM.

lpszSockAddress

A pointer to a string containing the network address of the connected socket, a dotted number such as "128.56.22.8".

Remarks

Call the Create member function after constructing a socket object to create the Windows socket and attach it. Create then calls Bind to bind the socket to the specified address. The following socket types are supported:

Note   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.

For more information about stream and datagram sockets, see the articles Windows Sockets: Background, Windows Sockets: Ports and Socket Addresses, and Windows Sockets: Using Sockets with Archives in Visual C++ Programmer’s Guide and Windows Sockets Programming Considerations in the Win32 SDK documentation.

CSocket OverviewClass MembersHierarchy Chart

See Also   CAsyncSocket::Create, CAsyncSocket::Bind