共用方式為


CAsyncSocket::GetPeerNameEx

Call this member function to get the address of the peer socket to which this socket is connected (handles IPv6 addresses).

BOOL GetPeerNameEx( 
   CString& rPeerAddress, 
   UINT& rPeerPort  
);

Parameters

  • rPeerAddress
    Reference to a CString object that receives a dotted number IP address.

  • rPeerPort
    Reference to a UINT that stores a port.

Return Value

Nonzero if the function is successful; otherwise 0, and a specific error code can be retrieved by calling GetLastError. The following errors apply to this member function:

  • WSANOTINITIALISED   A successful AfxSocketInit must occur before using this API.

  • WSAENETDOWN   The Windows Sockets implementation detected that the network subsystem failed.

  • WSAEFAULT   The lpSockAddrLen argument is not large enough.

  • WSAEINPROGRESS   A blocking Windows Sockets call is in progress.

  • WSAENOTCONN   The socket is not connected.

  • WSAENOTSOCK   The descriptor is not a socket.

Remarks

This function is the same as CAsyncSocket::GetPeerName except that it handles IPv6 addresses as well as older protocols.

Requirements

Header: afxsock.h

See Also

Reference

CAsyncSocket Class

Hierarchy Chart

CAsyncSocket::Bind

CAsyncSocket::Connect

CAsyncSocket::Create

CAsyncSocket::GetSockName