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

  • Home
  • SEARCH
  • 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 7522543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:33:13+00:00 2026-05-30T02:33:13+00:00

I am working on a TcpClient Asynchronous requesting WPF project. In which I have

  • 0

I am working on a TcpClient Asynchronous requesting WPF project. In which I have written some code when ever client gets disconnected with out network lost due to socket disconnected. Its working fine, and when the socket is removed/unplugged also on the server side no event is firing or no exception recieved to make the client status disconnected. I have seen about this issue in many sites, every where people used to say to use the Socket.Poll method but which is not working in my case. The SelectMode.SelectRead is always returning true when the client connected or disconnected, so I cant find any alternative.

So, I am posting my question here to know how to find when a client socket is unplugged/network access has been lost in asynchronous mode. I have tried with following code, any how its not working.

    void CheckSocketStatus()
    {
        try
        {
            while (true)
            {
                System.Threading.Thread.Sleep(1000);
                if(!mobjClient.Client.Poll(0,SelectMode.SelectWrite))
                {
                    break;
                }
            }
        }
        catch(SocketException soex)
        {

        }
    }

Hope someone can help me.

  • 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-30T02:33:14+00:00Added an answer on May 30, 2026 at 2:33 am

    It is correct that this cannot be used to detect certain connection problems as by the documentation that states:

    This method cannot detect certain kinds of connection problems, such as a broken network cable, or that the remote host was shut down ungracefully. You must attempt to send or receive data to detect these kinds of errors.

    You should probably consider not relying on a persistent connection and instead open/close it on demand. Nevertheless, if you need some kind of connection state information, the unfortunate conclusion is that the underlying architecture does not provide it. You’ll have to do it by periodically exchanging packets and catching errors.

    This is also what the documentation on the Connected property of TcpClient suggests:

    Because the Connected property only reflects the state of the connection as of the most recent operation, you should attempt to send or receive a message to determine the current state. After the message send fails, this property no longer returns true. Note that this behavior is by design. You cannot reliably test the state of the connection because, in the time between the test and a send/receive, the connection could have been lost. Your code should assume the socket is connected, and gracefully handle failed transmissions.

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

Sidebar

Related Questions

I am working on a network project which uses TCPListener and TCPClient. I have
I have the following code in C#: Console.WriteLine(Connecting to server...); TcpClient client = new
Working on a project at the moment and we have to implement soft deletion
Working with python interactively, it's sometimes necessary to display a result which is some
I'm currently working on an asynchronous TCP-Client. I am able to send and receive
Currently I am working on a network project which includes connecting to tcp servers
Working with some basic java apps on CentOS 5 linux and I have my
I have a question, I'm currently working on a little project of mine and
I have been working on a (relatively) simple tcp client/server chat program for my
When my Tcpclient is working , with this code : TCPClient.Disconnect; TCPClient.Connect; I get

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.