By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,784 Members | 1,188 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,784 IT Pros & Developers. It's quick & easy.

Async Socket Disconnect Problem

P: n/a
I have an Asynchronous socket that sends data to a server for credit
card approvals. The socket is kept alive by the server through a
heartbeat that sends a "beat" every 90 seconds. Trouble is that the
network is unreliable at times and thus the server will drop my
connection from time to time. I need to code around this so I can
reconnect to the server whenever this happens.

THE PROBLEM:
The Connected, Poll, and Available properties and methods are all
telling me that I am working, but I know for a fact that the server is
expecting me to reconnect because I stopped my heartbeat. This is all
verified so please don't question the scenario, I just need help
finding out that my connection is no longer valid through some
property on the .NET Socket or something in the Async callbacks that I
may be missing. Any help, please!!!!
Doug M.
Feb 12 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
do**********@gmail.com wrote:
I have an Asynchronous socket that sends data to a server for credit
card approvals. The socket is kept alive by the server through a
heartbeat that sends a "beat" every 90 seconds. Trouble is that the
network is unreliable at times and thus the server will drop my
connection from time to time. I need to code around this so I can
reconnect to the server whenever this happens.

THE PROBLEM:
The Connected, Poll, and Available properties and methods are all
telling me that I am working, but I know for a fact that the server is
expecting me to reconnect because I stopped my heartbeat. This is all
verified so please don't question the scenario, I just need help
finding out that my connection is no longer valid through some
property on the .NET Socket or something in the Async callbacks that I
may be missing. Any help, please!!!!
There is no such property. This is an inherent feature/limitation of TCP/IP.
None of these properties work unless the connection is being actively used
(including active disconnection).

The *only* way to detect a broken connection is to send data on it and find
out that it doesn't work. You will only get an error on receiving data if
the other side shuts down the connection and your side sees it (which is not
the case for unexpected drops). In other words: you (the client) should be
sending heartbeats, and as soon as that fails, your connection will break
and you should reconnect. Ideally, the server should send replies to that
heartbeat that you can timeout on, so you can detect a one-sided connection.
The other way around works as well, but the bottom line is that you should
be sending.

If you *are* doing all that and you're still not detecting a broken
connection, you should check your firewall configuration (on either end). It
may be keeping the connection open improperly.

Note that even with heartbeats, you get no guarantee of uninterrupted
service, and sending a request can always fail, even if you just had a good
heartbeat. Your protocol should work exactly as well without using *any*
heartbeats and rebuilding the connection on the first send failure (since a
TCP/IP connection can remain open indefinitely through failures, as long as
it's up when it's actually used). Your protocol should have reasonable
timeouts for detecting these failures in an acceptable timeframe. The only
advantage to heartbeats is that you stand a better chance (on average) of
having a usable connection when a request comes in.

--
J.
Feb 12 '08 #2

P: n/a
Pete,

Sorry if offended anyone, I was just trying to impress that I know
that my test for getting the connection to drop is fine and I didn't
want people to get hung up on that detail. As for the heartbeat, this
is an old system that has thousands of POS systems requesting credit
card auths and the heartbeat is to let the server know that things are
still alive. Unfortunately I cannot go into any more detail, non-
disclosure. I thank you for your help and the scenario you described
is my current way of prevention, trouble is that if a request comes
through inbetween heartbeats I'll have no idea and the request will be
lost. Even bigger than that is that the BeginSend method and the
AsyncResult have no errors, exceptions, or invalid return data. So
there is my problem, no way of telling if the current send is getting
through. Thanks...
Doug M.
Feb 12 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.