server status

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

Guest

I have a server utility which uses Sockets.TcpListener to listen to client
connections. Clients connect using using s.Connect(EPhost) where s is

s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp );

Now unexpectedly server goes down, but client still get s.Connected property
to true. What is best way (less resource intensive) to find out that server
is now down so that client can start making reconnection attempts to get
updates from server? I need to start making reconnection attempts as soon as
server is down.

regards
Sachil
 
There are two ways:
1) you'll "try/catch" all your socket operations
2) you can set socket option named SocketOptionName.KeepAlive.

Using 2-nd way will let you know about connection problems earlier.
However, there is no good way to determine if the server is down. Because
server may experiense critical failure - in this case he won't be able to
notify client about it, and if there's no keep-alives, client endpoint will
only get the info about connection problem during send operation, when
timeout will exceed.

IMHO the best choice will be the combination of 2 methods. In this case
you'll get know about connection problem asap, and will handle the exception
during I/O appropriately
 
Thanks for quick reply.

How about having a low priority thread which keeps track server status
(along with doing other things)?
Is there any way in .net i can find if there is any server running on
machine A at port P? I agree my question is same, it's just a different way
to put it, but i am looking for a generic approach to this issue.

regards
Sachil
 
Low priority thread may be good solution if there is little number i/o
socket operations.

Otherwise the situation may arise when thread finished checking server,
after this server fails, and you receive excpeption on socket.
If you'll check the server too intensively - you can introduce network
congestion.

To detect if server is listening on specified port - you'll have to
introduce the connection to that machine.

You can write a port scanner, and to optimize it you can utilize Raw sockets
and TCP handshake procedure.

While developing network application one cannot be always sure that server
is out there, the best approach is to suppose that failures will be frequent
situation.
 
Back
Top