Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7076967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:21:51+00:00 2026-05-28T06:21:51+00:00

Been trying some different ways of detecting if a remote Socket has disconnected. I

  • 0

Been trying some different ways of detecting if a remote Socket has disconnected.

I currently do this to check if a socket is connected.

public void CheckSocket()
{
    try
    {
        bool test1 = s.Poll(_MicrosecondFaultTolerance, SelectMode.SelectRead);
        bool test2 = (s.Available == 0);
        if (test1 && test2)
            _Active = false;
    }
    catch
    {
        _Active = false;
    }
}

This for some reason works perfectly on the first drop every time no questions asked but after that the check does not set _Active to false and thus the client is never considered “disconnected”. Are there any other ways i could test a Connection or have a more reliable result at all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:21:52+00:00Added an answer on May 28, 2026 at 6:21 am

    I’m not sure what you mean by “the first drop”, since once the connection under a socket has been dropped, the socket must be closed. That all depends on what you are doing outside of the CheckSocket() function. But assuming that’s all handled correctly, simply polling the socket will not work reliably if the underlying connection is idle.

    A disconnect can only be detected if there is some traffic on the underlying transport. If a connection is abandoned (not closed) while idle, it will quietly sit there forever. To detect an abandoned connection while idle, use setsockopt() with SO_KEEPALIVE. TCP will periodically exchange dummy traffic with the other side to test whether the connection is still alive and prevent any NAT or other dynamic routing rules from timing out. Note that it still may take 30 seconds or more to detect a drop, as that is TCP’s default timeout.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying this a couple of different ways, but it's not working for
I have been trying to find some resource on this topic for a while
I've been trying to find some manual information on this, but my search is
I've been trying to do this for some time unsuccesfully. I'll say in advance
I've been trying to implement unit testing and currently have some code that does
I have an app, and I'd need custom UITableViewCells, I've been trying different ways,
I've been trying differnt ways of approaching this, but I'm not having to much
new to jquery here but I'm trying to learn some different stuff that's been
I'm trying to sort some DIVS in different ways and I'm quite lost. I've
I have been trying different techniques while designing this application, which to me is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.