试试WSAAccept函数,后两个参数提供一个回调函数用于过滤SOCKET WSAAccept( __in SOCKET s, __out struct sockaddr* addr, __in_out LPINT addrlen, __in LPCONDITIONPROC lpfnCondition, __in DWORD dwCallbackData );lpfnCondition The address of an optional, application-specified condition function that will make an accept/reject decision based on the caller information passed in as parameters, and optionally create or join a socket group by assigning an appropriate value to the result parameter g of this function. If this parameter is NULL, then no condition function is called.dwCallbackData Callback data passed back to the application-specified condition function as the value of the dwCallbackData parameter passed to the condition function. This parameter is only applicable if the lpfnCondition parameter is not NULL. This parameter is not interpreted by Windows Sockets.
一般来说,服务器必须 accept 之后才能知道客户端的 ip 地址,方能进行判断
要在 accept 之前知道对方 ip 地址 ...可以试试修改协议报表头,让客户端发起连接时,在数据里面放入自己的 ip 地址 ...
在应用层,不accept,是不知道IP的
,套接字任何时刻都有关闭的的情况的
例如WINDOWS的IP策略 或防火墙.
__in SOCKET s,
__out struct sockaddr* addr,
__in_out LPINT addrlen,
__in LPCONDITIONPROC lpfnCondition,
__in DWORD dwCallbackData
);lpfnCondition
The address of an optional, application-specified condition function that will make an accept/reject decision based on the caller information passed in as parameters, and optionally create or join a socket group by assigning an appropriate value to the result parameter g of this function. If this parameter is NULL, then no condition function is called.dwCallbackData
Callback data passed back to the application-specified condition function as the value of the dwCallbackData parameter passed to the condition function. This parameter is only applicable if the lpfnCondition parameter is not NULL. This parameter is not interpreted by Windows Sockets.
感谢大家的建议,尤其感谢vocanicy的帮助