CSocketWrench::GetPeerPort Method  
 
INT GetPeerPort();

Returns the remote port number used by the client to establish the connection.

Parameters

None.

Return Value

If the method succeeds, the return value is the port number. If the method fails, the return value is INET_ERROR. To get extended error information, call GetLastError.

Remarks

The GetPeerPort method returns the port number that the socket is bound to on the remote host. If the current socket is a passive (listening) socket, and a client is attempting to establish a connection, this method will return the ephemeral port that the client is bound to.

It is not recommended that you use the client port number for anything other than informational and logging purposes. Do not make any assumptions about the specific port number or range of port numbers that a client is using when establishing a connection to the server. The ephemeral port number that a client is bound to can vary based on the client operating system.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cswsock11.h
Import Library: cswskv11.lib

See Also

GetLocalAddress, GetLocalName, GetPeerAddress