Socket

We have two applications - two sockets.
If on side of the one from applications
happened something , for example electricity cut ,and socket wasn't close
normally .How second size can get information about this - that socket wasn't close normally.
gula100399Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

danny_pavCommented:
when you just close the socket on one side, the other will get a close notification.  I would guess that would be the case with cutting the wire.  Try it and find out.
0
stefanrCommented:
You don't know that the connection is broken until you try to send something. That is why we often use a "heartbeat" message or something similar to be sure that the connection is up. If the heartbeat interval exceeds a predefined amount of time, we assume that the connection is broken and closes the socket.
0
danny_pavCommented:
I am assuming you are using MFC and CSocket.  

OK you can override the OnClose of CSocket.  You will get this when the other end closes the connection.  Check to see if this occurs when the wire gets cut.  I think it would.
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

bholzCommented:
Hi,

as stefanr said, you will not notice until your next attemptz to send or receive data. You will get a WSAECONNRESET error then. If if is important to recognize this kind of failure before sending/receiving again you have to use something like heartbeat messages.

Regards, Bernd


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
danny_pavCommented:
1.  Don't try to receive data if there is none.  You know when data is available because you get a OnReceive call.  You can't receive if the connection is broken.
2.  If the connection gets broken, you will get an OnClose call.  If you got an OnClose, you cannot send.  In your OnClose handler, why not set a flag telling that you cannot send.  Or delete the CSocketFile attached to that CSocket and set the pointer to it to NULL.  Check this before attempting to send.

Why do you need heartbeat messages?
0
bholzCommented:
Hi Danny,

you are assuming that gula is using the MFC socket version which is not known to be very good.

I am not sure how the MFC socket implementation handles the described scenario. Did you check that OnClose() is called as soon as you, let's say unplug your network cable? I don't think so. And if, this has to be realized by internal heartbeat messages...

Regards,

Bernd
0
danny_pavCommented:
This is in the MFC questions section.  Seems like a good assumption that he is using MFC.

I don't know that you get the OnClose as soon as the wire gets clipped.  I said "Check to see if this occurs when the wire gets cut.  I think it would."
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.