How can a client detect a close on the server?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am programming a server and a client for a PLC that runs under WinCE .NET
4.2pro.

I want to detect on client side when the server does a close.

So far I tried it like this:

(Client)
I put the actual socket into a fdset and check it with select for
WRITEability.

Is this correct??
In my case, after the server has closed, select returns 1 (instead of -1)
and when I look at the fdset, then is there the actual socket!! And not
modified with -1!
Or have I an incorrect implementation of WinSock???? Because when I check on
server side a Socket positiv for READability, then I know that a client is
"knocking" on the server's listener Port. In this case select works correct.

*please excuse my bad english* I hope you know what I mean... ;-)
 
9 out of 10 cases you should receive a data of the length of zero. When
you receive a data with the length of zero then that means the
connection was closed.
Is this perfect? No. It is not perfect.
For absolute tests you can do a Timed send. In most cases if the socket
is closed it will fail. Is this perfect also? No once again it is not
perfect. I have ran and developed network applications long enough to
see both methods not operate the way one would expect them. However
both are methods that "will work in most cases"
 
??? Sorry, I can't follow you....

Once again my question: Is it correct, that select (with a FDSet on write)
could detect on client side that the server has closed the connection?!?

If this isn't correct, tell me how to use select for detecting the server's
close on client side.
 
I have used prior methods where one Polls the socket or does some other
method and honestly it was never as reliable and the network
performance loss was simply not worth it.

As to whether that is "correct", I would read the MSDN Documentation on
the matter as they would have it best documented.
 
Back
Top