Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

A question on TCP SO_KEEPALIVE / WSAECONNRESET

Posted on 2001-08-12
7
Medium Priority
?
1,105 Views
Last Modified: 2007-12-19
Hi,
I need to detect if a TCP connection is broken.  At first, I tried to set SO_KEEPALIVE.  However, there is not parameter to set the timeout.  I know that in registry I can set the timeout (which default is 10 min for Windows), but this will affect all the TCP/IP connection.

I would like to take a second alternative: now and then call send() to transmit some dummy packet to another end. I expect the WSAECONNRESET error returned, which it does not, and after a few 10 secs, the select() returned error.  I run this test in a intranet, so I am not sure whether is it detected by Microsoft Network or TCP.

Can anybody help me?

Thanks
0
Comment
Question by:lsmgms
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 2

Expert Comment

by:sateesh_babu
ID: 6378957
When a client breaks a connection, select() returns with that socket descriptor set as "ready to read". When you actually do recv() from it, recv() will return 0. That's how you know the client has closed the connection.

Hope this helps!!!
Babu
0
 
LVL 1

Author Comment

by:lsmgms
ID: 6379235
Hi,
  From testing, looks like select() only return if the another end is closed such as shutdown or application quit.  It cannot detect situation such as network link broken.  Am I right?
0
 
LVL 2

Expert Comment

by:sateesh_babu
ID: 6379778
That is right, it cannot detect Network link broken. For such a purpose, the general way it is handled is to set a timeout value for the socket(data not received within 5 min.) and when the socket times out, close the socket. Or you can send a packet after the timeout value, and if you get an error, you can close the socket.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:lsmgms
ID: 6382439
I cannot use the timeout, because the data will randomly arrive (may be after a few mins).  

About send(), this is the question I have.  I still can call send() without any error return ( I think it is buffer), and after a few mins, then my select() thread will report error.  I would like to know whether this is detected by Microsoft Network or TCP.  I worry about this because the application has to ve able to run in internet, which current developed and tested in Intranet.

Thanks.
0
 
LVL 2

Expert Comment

by:sateesh_babu
ID: 6383072
The only was, as I see to tackle this problem is debugging with a prototype code. Write a small code that simulates your actual code, and try checking if you get the same result. Simulate the situation in the code.
   And what is this Microsoft Network? I think the error is not detected by the MS Network. And what is the timeout value you have set in the select() statement? Set it to NULL.
0
 

Accepted Solution

by:
le earned 150 total points
ID: 6407595
True. KEEP_ALIVE does not have a timeout parameter exposed to the caller. There is a way to configure timeout and number of retries in WIN registry. Look in MSDN. The real problem is: TCP/IP does not guaranty delivery.
First of all: recv checks if there is data in the driver buffer avaliable and returnes to the caller OK. So, network may be down (cable disconnected) and recv returnes OK - no data avaliable. Send returnes OK if data is placed in the local buffer. In short, if number of bytes written <>  number of bytes sent in syncronous mode you know that connection is lost. If all was written OK, you know ONLY that data is in the buffer.

KEEP_ALIVE default timeouts are set extrimely high (in essance, disabling keep alive functionality). Again you can change it by edditing registry.
The situation is even worse: keep alive functionality is VERY inconsistent accross different platforms. The best implementation is in WINDOWS NT. Windows 98 failes. Linix also fails unpredictably.

The right solution is to add keep alive sygnals to your application level protocol.

There is one more way to guaranty message delivery (all documentation strongly discorage this usage).
Namely disabling buffering at the end of every send operation:
int BuffSize = 0;
setsockopt(m_socket, SOL_SOCKET, SO_SNDBUF, (char*)(&BuffSize), sizeof(BuffSize));
You start writing with normal Buffer size and write all bytes (but one) in one call to send. Then change the option and sent the last byte with no buffering. With this option send returnes after the round trip is done and data is in receiving copmuter buffer (NOTE: not read by receivind application, just in the buffer).
The connection speed in this case will be 1/10 of your bandwidth.



0
 
LVL 1

Author Comment

by:lsmgms
ID: 6408434
Hi le,

I agree that what you said, but I would like to "temporary" unlock this question first to see whether I cam receive more comments.  

I know that application level protocol can solve this.  Unfortunately, I am using a standard protocol (ITU-H225) and not all of the vendors repsonse to the network status reqeust.

Currently what I am doing (which I am not satisfy yet) is:
create a separate thread, which now and then try to open a TCP connection to the destination.  If network broken, I will receive error from connect(). I don't like it because it will consume another connection.

The only thing I am confused is when I call send(), then after a while it may cause select() returned from error.  I would like to know whether this is caused by Ethernet network or TCP/IP.

I will not try to use the buffer approach, becuase of performance reason.

Thanks.

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

610 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