Hard closing Socket cannot be detected

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello Developers,
I have developed Server and Client applications that are communicating by
TCP/IP sockets. My application is developed on Visual C++ .NET Standard v2003
Windows Forms. When one of the program is closed unintensionally, other is
automatically trying to re-connect. But, whenever one of PC is turned off
hardly from ShutDown button or unplugging electric cable, I cannot detect the
loss of communication. If I send a command from working application to closed
application, I can detect loss of communication. I setted my sockets'
SO_KEEPALIVE = 1 and linger ON.
I am requesting your help.
Thank you very much in advance
--
~~~~~~~~~~~~~~~~~~~
İyi Çalışmalar
Alper AKÇAYÖZ (Bil Muh)

Wish You Good Work
Alper AKCAYOZ (Bil Muh)
 
Alper said:
automatically trying to re-connect. But, whenever one of PC is turned off
hardly from ShutDown button or unplugging electric cable, I cannot detect the
loss of communication. If I send a command from working application to closed
application, I can detect loss of communication. I setted my sockets'
SO_KEEPALIVE = 1 and linger ON.

This has nothing to do with VS, VC, .NET, Windows, Unix etc., this is
how TCP/IP works. If, for instance, you unplug the cable, and plug it in
again, your application won't even notice that the cable was unplugged.
That's a Good Thing.

You don't need to detect that the peer didn't *received* the message,
you need to detect that the peer didn't *processed* the message. You
detect this by waiting on peer's response, and declaring a timeout if
you waited long enough. If you want to know whether peer processed the
message your communication protocol *must* have the response from peer.
If the current protocol doesn't have the response you *must* change the
protocol.

SO_KEEPALIVE is not intended for this purpose, and shouldn't be used for
it. SO_KEEPALIVE is used by servers (http server, ftp server...). Linger
also isn't intended for this purpose. The only solution is to use
timeout mechanism, and it's a programmer's job to implement it.

To avoid logical endless loop only one side should care about timeouts,
and it's usually the client (the one that sends something and expects an
answer).

Last note: if the client declares a timeout that doesn't mean that the
server didn't processed the message...
 
My purpose is to receive group of data from server continuously, and display
them on clients Windows forms. I am using TCP protocol. When receiving data
from server, generally, client does only displaying works. If Server's power
is off, client does anything, it waits. This waiting is not for
re-connecting. If I send a command to server, client understands that
communication is broken. So, it does re-connecting works at that time.
I thank your kind consideration.

--
~~~~~~~~~~~~~~~~~~~
İyi Çalışmalar
Alper AKÇAYÖZ (Bil Muh)

Wish You Good Work
Alper AKCAYOZ (Bil Muh)
 
Alper said:
My purpose is to receive group of data from server continuously, and display
them on clients Windows forms. I am using TCP protocol. When receiving data
from server, generally, client does only displaying works. If Server's power
is off, client does anything, it waits. This waiting is not for
re-connecting. If I send a command to server, client understands that
communication is broken. So, it does re-connecting works at that time.
I thank your kind consideration.

If I understand correctly, everything works but you're still worried
about something. Take a look at this FAQ:

http://tangentsoft.net/wskfaq/

Especially, take a look at:

http://tangentsoft.net/wskfaq/newbie.html#abnormalclose
 
I thank you very much for your explanations and usefull urls.
I wish you good day.
--
~~~~~~~~~~~~~~~~~~~
İyi Çalışmalar
Alper AKÇAYÖZ (Bil Muh)

Wish You Good Work
Alper AKCAYOZ (Bil Muh)
 
As you understand, everything is working properly. But I want to be more
sure. If server is down because electric is off, I dont want client to be
waiting more time. That is why, I want to detect communication errors as soon
as possible. Other connection errors are working properly. If cable is
unplugged, client waits some time, later on when it detects, it tries to
re-connect. that is fine.

--
~~~~~~~~~~~~~~~~~~~
İyi Çalışmalar
Alper AKÇAYÖZ (Bil Muh)

Wish You Good Work
Alper AKCAYOZ (Bil Muh)
 
Back
Top