Solved

CAsyncSocket and broken network cable

Posted on 1998-06-10
7
370 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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