在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 the
AcceptExfunction 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 套接口未连接。
本文详细介绍了在使用AcceptEx函数后如何正确设置SO_UPDATE_ACCEPT_CONTEXT选项,以便通过getsockname和getpeername函数获取正确的本地和远程套接字地址。若不进行此设置,则可能遇到WSAENOTCONN错误。
1385

被折叠的 条评论
为什么被折叠?



