Hi, everyone,

I am trying to test a client/server solution that uses the .NET Socket class
(blocking mode on the server). I need the server to be able to verify that a
socket is still valid in case the client app drops the connection (i.e. the
client app crashes). The Poll method and the Available and Connected
properties always return the same value regardless if the connection is
valid or not. Using the Receive(w/ Peek) method also does not work since it
waits for incoming data if the connection is valid. Any suggestions on how
to efficiently check the connection?

Thanks,
Bob L.

Re: Dead Socket Detection? by David

David
Fri Jul 23 17:55:49 CDT 2004


"Bob L." <nospam.info2@libertyfamily.net> wrote in message
news:euFfZrPcEHA.212@TK2MSFTNGP12.phx.gbl...
> Hi, everyone,
>
> I am trying to test a client/server solution that uses the .NET Socket
class
> (blocking mode on the server). I need the server to be able to verify that
a
> socket is still valid in case the client app drops the connection (i.e.
the
> client app crashes). The Poll method and the Available and Connected
> properties always return the same value regardless if the connection is
> valid or not. Using the Receive(w/ Peek) method also does not work since
it
> waits for incoming data if the connection is valid. Any suggestions on how
> to efficiently check the connection?
>


Aparently there are only two ways to do this.

Build a periodic "ping" into your conversation protocol or use the
SO_KEEPALIVE socket option. The problem with the SO_KEEPALIVE option is
that the keepalive packets are sent, by default, only every two hours. This
interval is configured in the registry and is system-wide.

From
http://www.microsoft.com/windows2000/techinfo/howitworks/communications/networkbasics/tcpip_implement.asp


HKEY_LOCAL_MACHINE
\SYSTEM
\CurrentControlSet
\Services:
\Tcpip
\Parameters

KeepAliveTime
Key: Tcpip\Parameters
Value Type: REG_DWORD?time in milliseconds
Valid Range: 1?0xFFFFFFFF
Default: 7,200,000 (two hours)
Description: The parameter controls how often TCP attempts to verify that an
idle connection is still intact by sending a keep-alive packet. If the
remote system is still reachable and functioning, it acknowledges the
keep-alive transmission. Keep-alive packets are not sent by default. This
feature may be enabled on a connection by an application.

David



Re: Dead Socket Detection? by Bob

Bob
Fri Jul 23 18:49:03 CDT 2004

David,

Thanks for the ideas. I was trying to avoid the "ping" idea since this
solution is primarily a one way conversation: the client asking the server
for information. However, every two hours for the keep alive is acceptable
in our case, since it is primarily for cleanup and freeing resources.

Thanks again,
Bob

"David Browne" <davidbaxterbrowne no potted meat@hotmail.com> wrote in
message news:eUixzgQcEHA.2908@TK2MSFTNGP10.phx.gbl...
>
> "Bob L." <nospam.info2@libertyfamily.net> wrote in message
> news:euFfZrPcEHA.212@TK2MSFTNGP12.phx.gbl...
> > Hi, everyone,
> >
> > I am trying to test a client/server solution that uses the .NET Socket
> class
> > (blocking mode on the server). I need the server to be able to verify
that
> a
> > socket is still valid in case the client app drops the connection (i.e.
> the
> > client app crashes). The Poll method and the Available and Connected
> > properties always return the same value regardless if the connection is
> > valid or not. Using the Receive(w/ Peek) method also does not work since
> it
> > waits for incoming data if the connection is valid. Any suggestions on
how
> > to efficiently check the connection?
> >
>
>
> Aparently there are only two ways to do this.
>
> Build a periodic "ping" into your conversation protocol or use the
> SO_KEEPALIVE socket option. The problem with the SO_KEEPALIVE option is
> that the keepalive packets are sent, by default, only every two hours.
This
> interval is configured in the registry and is system-wide.
>
> From
>
http://www.microsoft.com/windows2000/techinfo/howitworks/communications/networkbasics/tcpip_implement.asp
>
>
> HKEY_LOCAL_MACHINE
> \SYSTEM
> \CurrentControlSet
> \Services:
> \Tcpip
> \Parameters
>
> KeepAliveTime
> Key: Tcpip\Parameters
> Value Type: REG_DWORD-time in milliseconds
> Valid Range: 1-0xFFFFFFFF
> Default: 7,200,000 (two hours)
> Description: The parameter controls how often TCP attempts to verify that
an
> idle connection is still intact by sending a keep-alive packet. If the
> remote system is still reachable and functioning, it acknowledges the
> keep-alive transmission. Keep-alive packets are not sent by default. This
> feature may be enabled on a connection by an application.
>
> David
>
>



Re: Dead Socket Detection? by John

John
Sat Jul 24 07:57:24 CDT 2004

"Bob L." <nospam.info2@libertyfamily.net> wrote in message
news:euFfZrPcEHA.212@TK2MSFTNGP12.phx.gbl...
> Hi, everyone,
>
> I am trying to test a client/server solution that uses the .NET Socket
class
> (blocking mode on the server). I need the server to be able to verify that
a
> socket is still valid in case the client app drops the connection (i.e.
the
> client app crashes). The Poll method and the Available and Connected
> properties always return the same value regardless if the connection is
> valid or not. Using the Receive(w/ Peek) method also does not work since
it
> waits for incoming data if the connection is valid. Any suggestions on how
> to efficiently check the connection?

Why do you need to know the connection is open?

At any rate, about the only way to know that the connection is open is to
send something and then to get a response to what you sent. Sending on a
broken connection may succeed at first. Receiving on a broken connection may
also succeed. The only way to be sure is to send a "ping" message, including
a unique value, and then to receive a response which contains the same
unique value. That will tell you that the connection was open at the time
you sent the unique value.
--
John Saunders
johnwsaundersiii at hotmail