473,750 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Async Socket Disconnect Problem

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
2 4340
do**********@gm ail.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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
18133
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed as I find appropriate. I am using the socket asynchronously by calling the BeingSend and BeginReceive calls. I would like to be able to call shutdown and close asynchronously if possible.
5
11719
by: mscirri | last post by:
The code below is what I am using to asynchronously get data from a PocketPC device. The data comes in fine in blocks of 1024 bytes but even when I send no data from the PocketPC constant blocks of 1024 with all values set to Null arrive. Other than examine a block of 1024 to see if the entire block is null, is there any other way to determine if , say a chat message "Hi Charlie" has been received completely?
6
3823
by: Shak | last post by:
Hi all, Three questions really: 1) The async call to the networkstream's endread() (or even endxxx() in general) blocks. Async calls are made on the threadpool - aren't we advised not to cause these to block? 2) You can connect together a binaryreader to a networkstream:
8
11018
by: Dinsdale | last post by:
I am trying to write a Tcp "Server" that opens a class that wraps a tcp socket when a new connection is made (Listener.AcceptSocket()). Everything is going swimmingly except when I try to close the socket during a read and I get the following error: <error_msg> An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in system.dll Additional information: The I/O operation has been aborted because of
3
2585
by: xincmu | last post by:
I built a very basic server-client in C#. When my server disconnects from the client, the socket at the server is already disconnected, but the socket the client remains open. I used the sample code in .Net's documentation to disconnect: socket.Shutdown( SocketShutdown.Both ); socket.Disconnect( false ); I also tried
11
8614
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling mechanisms. I use a non-blocking approach for this, using the call to 'poll' to support the async mechanism - rather than the 'begin' and 'end' functions. I already found that connecting doesn't set the "isconnected" variable correctly...
15
8411
by: dennis.richardson | last post by:
Greetings all. Here's a problem that's been driving me nuts for the last 48 hours. I'm hoping that someone has come across this before. I have a C# Application that reads a UDP broadcast (asynchronously). Then it repackages these UDP packets and sends them to a subscriber via TCP. Now, I can read the UDP stream all day long without the application
3
14431
by: Cheryl | last post by:
Hi. I am having a problem on handling asynchronous sockets in C#. I implemented a pair of client and server sockets. The connection is ok when first connected. However, when I turned off the server socket, the client is able to connect, but cannot send anything out. It seems that the Socket.Connected is false but I received no disconnection event. Any idea on how to solve the problem? Thanks.
1
20640
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but I don't see the error): "System.IO.IOException: Unable to read data from the transport connection:A blocking operation was interrupted by a call to WSACancelBlockingCall"
0
8839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9584
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9344
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8264
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6810
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4893
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.