Solved

CAsyncSocket and broken network cable

Posted on 1998-06-10
7
392 Views
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
Mike
0
Comment
Question by:mike_marquet
[X]
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
7 Comments
 
LVL 32

Accepted Solution

by:
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.
0
 

Author Comment

by:mike_marquet
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 ?

Thanks,
Mike
0
 
LVL 32

Expert Comment

by:jhance
ID: 1317823
I don't understand.  How can your remote computer receive the data if you've cut the network cable?  Please explain.
0
Independent Software Vendors: 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

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

Expert Comment

by:jhance
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.
0
 
LVL 32

Expert Comment

by:jhance
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.
0
 

Author Comment

by:mike_marquet
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.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CRON statement to run every 3 minutes except on Monday morning 12am to 2am 7 114
canBalance challenge 34 105
Fibonacci challenge 11 136
changeXy challenge 13 93
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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