473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Hard closing Socket cannot be detected

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)
Nov 17 '05 #1
5 3484
Alper AKCAYOZ wrote:
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...
Nov 17 '05 #2
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)
"Mihajlo Cvetanović" wrote:
Alper AKCAYOZ wrote:
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...

Nov 17 '05 #3
Alper AKCAYOZ wrote:
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
Nov 17 '05 #4
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)

Nov 17 '05 #5
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)
"Mihajlo Cvetanović" wrote:
Alper AKCAYOZ wrote:
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

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the...
4
by: flupke | last post by:
Hi, I have a gui (made in wxPython) that enables a user to connect to a server and issue some commands. The problem occurs when i try to disconnect the client. It exits but it doesn't return to...
1
by: Daniel | last post by:
after opening socket, sending data then closing socket 3000 times i get "Only one usage of each socket address" what am i doing wrong? is there some thing else i need to do to free up the socket...
5
by: Alper AKCAYOZ | last post by:
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...
0
by: Alper AKCAYOZ | last post by:
Hello Developers, I am developing Server and Client applications at Visual C++ .NET Windows Forms. They are communicating with each others by TCP/IP Sockets. While there is a communication between...
1
by: David | last post by:
Having:Socket mysocket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); I cannot execute mysocket.Close() after executing mysocket.BeginAccept(new...
9
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so...
8
by: Dinsdale | last post by:
I am trying to write a Tcp "Server" that opens a class that wraps a tcp socket when a new connection is made (Listener.AcceptSocket()). Everything is going swimmingly except when I try to close the...
4
by: Funke | last post by:
Assume that in C#, I create a server socket (listener) and code to start new threads with each connection using BeginAccept(). After some time, I have three threads running, each with their own...
4
by: O.B. | last post by:
I have a socket configured as TCP and running as a listener. When I close socket, it doesn't always free up the port immediately. Even when no connections have been made to it. So when I open...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.