在AcceptEx之后要设置
int err = setsockopt( pWxOl->m_sock,
SOL_SOCKET,
SO_UPDATE_ACCEPT_CONTEXT,
(char *)&sListenSocket,
sizeof(sListenSocket) );
这样在后面getsockname和getpeername才能拿到真正的IP地址。
When using AcceptEx, the GetAcceptExSockaddrs function must be called to parse the buffer into its three distinct parts (data, local socket address, and remote socket address). On Windows XP and later, once theAcceptExfunction completes and the SO_UPDATE_ACCEPT_CONTEXT option is set on the accepted socket, the local address associated with the accepted socket can also be retrieved using the getsockname function. Likewise, the remote address associated with the accepted socket can be retrieved using the getpeername function.
否则会出现 WSAENOTCONN 套接口未连接。
浙公网安备 33010602011771号