CAsyncSocket::Connect

BOOL Connect( LPCTSTR lpszHostAddress, UINT nHostPort );

BOOL Connect( const SOCKADDR* lpSockAddr, int nSockAddrLen );

Return Value

Nonzero if the function is successful; otherwise 0, and a specific error code can be retrieved by calling GetLastError. If this indicates an error code of WSAEWOULDBLOCK, and your application is using the overridable callbacks, your application will receive an OnConnect message when the connect operation is complete. The following errors apply to this member function:

Parameters

lpszHostAddress

The network address of the socket to which this object is connected: a machine name such as “ftp.microsoft.com”, or a dotted number such as “128.56.22.8”.

nHostPort

The port identifying the socket application.

lpSockAddr

A pointer to a SOCKADDR structure that contains the address of the connected socket.

nSockAddrLen

The length of the address in lpSockAddr in bytes.

Remarks

Call this member function to establish a connection to an unconnected stream or datagram socket. If the socket is unbound, unique values are assigned to the local association by the system, and the socket is marked as bound. Note that if the address field of the name structure is all zeroes, Connect will return zero. To get extended error information, call the GetLastError member function.

For stream sockets (type SOCK_STREAM), an active connection is initiated to the foreign host. When the socket call completes successfully, the socket is ready to send/receive data.

For a datagram socket (type SOCK_DGRAM), a default destination is set, which will be used on subsequent Send and Receive calls.

CAsyncSocket OverviewClass MembersHierarchy Chart

See Also   CAsyncSocket::Accept, CAsyncSocket::Bind, CAsyncSocket::GetSockName, CAsyncSocket::Create, CAsyncSocket::AsyncSelect