Thx,
I can not use remoting, because the connection has to be from a java
client on a web-page to a c# service.
But I will find out everything.
Thx alot.
Anders,
You may have already found an answer for this, if not, hopefully this
helps.
The only way the client can know that the connection is gone, is if the
connection is closed by the server, or the client tries to send a data
packet, but hits its timeout period on the send method.
If the connection is lost, for example a router dies, then the only way to
know the connection is gone, is from a timeout, as you will never get the
shutdown (fin) message from the socket that initiated the shutdown/close.
You have two simple options that I can think of off the top of my head.
You can make the clients repond to the servers data, and have the
SendTimeout option set on the client sockets.
Below is from the MSDN help.
// Send operations will time-out if confirmation
// is not received within 1000 milliseconds.
s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout,
1000);
Your other options is if the server is known to always send data at a
specific interval, then you can use a timer to watch for a missed packet.
Or you can send Keep-Alive messages every 10 seconds, if the data is not
regular enough, or you don't want the sockets locked for longer than
necessary with a lost connection.
So if the server sends "Alive" every 5 seconds, then set a timer's timeout
period to 10 seconds. Whenever any data arrives on the socket, reset the
timer. If the timers Elapsed event is raised, then you know the server is
possibly not responding.
For more detail on Socket programming for C#, you can not go past Richard
Blum's book "C# Network Programming" - published by Sybex.
Scott Gaitskell