CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2006

    Talking does os close a tcp connection due to idleness?

    we have implemented a remote control program.
    we have noticed that if an user doesn't send any control command for a long time (for example about one to two hours), the socket gets closed for some reason.

    I have googled about this problem, it seems that tcp protocol doesn't have this rule. is this something introduced by the os? is sending heartbeat packet the only solution? is there any tcp socket flag I can tweak to disable this disconnection behavior ?

  2. #2
    Join Date
    Jan 2006
    Fox Lake, IL

    Re: does os close a tcp connection due to idleness?

    not if the machine goes into standby, or is shutdown. logmein rescue has the ability to log in to any saved machine

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2000
    Belgium (Europe)

    Re: does os close a tcp connection due to idleness?

    It's not part of TCP, but it is part of the OS to attempt to recover/recycle unused connections.
    Without a feature like this, it would be very easy for a malicious program to starve the server of resources/sockets.

    There's not typically anything you can do to prevent it. IIRC there are some registry settings on Windows that prevent this on the server side, but enabling them is likely to open your server for a lot of hurt.

    So in short, your app (and server) needs to find a way to handle disconnects. Many TCP based programs have a 'reconnect' type option for this, this could be automatic or manual.
    You can prevent the server side from closing the connection via a "keep alive" type heartbeat/pulse. Some apps need this explicitly, some apps send enough data on a regular basis to not need an explicit heartbeat.
    But even with a regular data traffic, you can still get disconnects for various reasons. Networks are somewhat unreliable.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.