Originally posted by: zhong
It will waste a great lot system's resource when calling function of recv() using MSG_PEEK flag.
ReplyOriginally posted by: Seba
I get an error thrown by the last MessageBox in the chatserver.....why ?
ReplyOriginally posted by: Lee
If you require notification of a socket being closed then try using the CAsyncSocket class which has a notification built in. This will let you know the moment a socket has been closed - either cleanly or abortively. What it will not tell you (and neither will the HasConnectionDropped() function) is that the network has failed - ie. part of the physical path between two computers has been lost.
HasConnectionDropped() relies on detecting data to be read on the input buffer (using select()). If the connection has been severed there will be no data and select will return zero and bConnDropped will be FALSE. Curiously bConnDropped will also be FALSE if select() returns SOCKET_ERROR. Why do you not handle this case?
The only way (that I know of) to detect network failures is to check for errors when writing data to a socket.
ReplyOriginally posted by: Sandman
the way to detect abnormally closed sockets explained above
works well, in fact that's the way that I found when I was experimenting hard to get the solution of that problem, but,
this approach doesn't work when the box on the other end is
TURNED THE POWER OFF, also getsockopt with SO_ERROR doesn't tell anything sensible about it. Also I tried to send keep alives, but no any error I could get neither with peeking described, nor with select with filled exceptfds parameter, nor with getsockopt with SO_ERROR option. MSDN says about keep-alives smth like: a winsock provider does not need to support keepalives..., does it mean that ms implementation of winsocks doesn't support them ?
If somebody know, how to deal with that problem, pls email me or leave comment here
Originally posted by: Alan
Set the socket option to send keepalive signals. These are packets transparent to the application layer. When the remote box or router between boxes goes down, the keepalive will detect it.
Reply