Solved

CAsyncSocket and broken network cable

Posted on 1998-06-10
7
345 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
  • 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now