CAsyncSocket and broken network cable

Posted on 1998-06-10
Last Modified: 2013-11-20
I have created a client/server application using CAsyncSocket class.
It works very fine. But my question is :

1°) I make a connection to the server side.
2°) When the connection is establish, I 'cut' the physical network cable.
3°) How can these applications know that the connection is broken ?

Because when I send a packet to the other side (with CAsyncSocket::Send), the function
returns OK, send succefull.

How to know it ?

Thanks for response
Question by:mike_marquet
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
LVL 32

Accepted Solution

jhance earned 20 total points
ID: 1317821
CAsyncSocket::Send() will only return an error if you are trying to send to an invalid socket or otherwise pass it bad parameters.  Since you have validly opened the CAsyncSocket, Send() believes it's OK to accept the data.  It has no way of knowing that you have cut the cable.  The only way to detect this problem is to use a timer.  After some reasonable amount of time (which you determine), if the OnSend() callback has not been received, then you determine that the connection has failed and notify the user, retry, give up, or whatever corrective action you decide to use.

Author Comment

ID: 1317822
But there is an other error, when I send my data, the OnSend handler is never posted !
But the remote computer has received the datas.
I become an OnSend data the first time the socket is connected to remote computer and that of both side.
Why ?

Must I set an option some where, and if yes where ?

LVL 32

Expert Comment

ID: 1317823
I don't understand.  How can your remote computer receive the data if you've cut the network cable?  Please explain.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 32

Expert Comment

ID: 1317824
I don't understand.  How can your remote computer receive the data if you've cut the network cable?  Please explain.
LVL 32

Expert Comment

ID: 1317825
You haven't posted any code but, in order to use the OnSend virtual function of CAsyncSocket, you must derive your own class from CAsyncSocket so that you can define your own OnSend class.  You then would add an instance of myCAsyncSocket to your application and it's OnSend member function would get called.
LVL 32

Expert Comment

ID: 1317826
BTW, is there a particular reason why you are using CAsyncSocket instead of CSocket?  I find that it's often easier to use the blocking CSocket calls and put them in a thread and then use WaitforSingleObject on the thread than to manage CAsyncSocket callback messages.  It gives you greater control over what you are waiting for.  If you put your Send in a thread, the call will hang until the data is sent.  Now your WaitForSingleObject can wait on the thread until it completes or your timeout happens.  If a timeout occurs, you can assume the network is down and cancel the send operation and recover grecefully.

Author Comment

ID: 1317827
When the cable is broken, the send function says that he has send data succefully.
It seams that the socket hasn't sea that the connection is broken.
He sends the data, but I never became an error ? (such as OnSend with error code).

When I says I using CAsyncSocket, I meen that I have derived from this class.
Replace all CAsyncSocket by CMyAsyncSocket.

I'm using CAsyncSocket for the callbacks functions and for non blocking socket.


Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 110
Windows Drag & Drop Location 2 117
post4 challenge 28 122
scoreUp challenge 14 74
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question