473,386 Members | 1,668 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 3485
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.