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

Re: server status by Vadym

Vadym
Tue Oct 18 09:18:26 CDT 2005

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

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com


"Sachil" <Sachil@discussions.microsoft.com> wrote in message
news:9F0F267E-361F-4FEE-82F4-EB9DA4D545A9@microsoft.com...
> 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
>
>



Re: server status by Sachil

Sachil
Tue Oct 18 10:25:04 CDT 2005

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

"Vadym Stetsyak" wrote:

> 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
>
> --
> Vadym Stetsyak aka Vadmyst
> http://vadmyst.blogspot.com
>
>
> "Sachil" <Sachil@discussions.microsoft.com> wrote in message
> news:9F0F267E-361F-4FEE-82F4-EB9DA4D545A9@microsoft.com...
> > 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
> >
> >
>
>
>

Re: server status by Vadym

Vadym
Tue Oct 18 11:19:37 CDT 2005

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.

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com


"Sachil" <Sachil@discussions.microsoft.com> wrote in message
news:84E73127-78B4-4129-9247-DA578D552EA2@microsoft.com...
> 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
>
> "Vadym Stetsyak" wrote:
>
> > 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
> >
> > --
> > Vadym Stetsyak aka Vadmyst
> > http://vadmyst.blogspot.com
> >
> >
> > "Sachil" <Sachil@discussions.microsoft.com> wrote in message
> > news:9F0F267E-361F-4FEE-82F4-EB9DA4D545A9@microsoft.com...
> > > 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
> > >
> > >
> >
> >
> >