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 6687767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:19:38+00:00 2026-05-26T05:19:38+00:00

Can it happen that a socket client closes connection and the server doesen’t know

  • 0

Can it happen that a socket client closes connection and the server doesen’t know this ?
I received several error on the event BeginReceive() in C#.
How to check if the client is still alive and in which places of my program would be better to place this checks ?

  • 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-26T05:19:39+00:00Added an answer on May 26, 2026 at 5:19 am

    There are several kinds of “closed connections” when programming with sockets. (I’ll use the BSD-derived system call names for the socket operations, I hope they kept similar names through the changes to C#.)

    • The client program closes the socket using shutdown() or close(). When this happens, TCP will send a FIN packet to your server. This will show up as a closed socket in your server when you try to read beyond the last byte of data sent by the client. The next read() will probably throw an exception or error condition. (Varies by environment.) This condition is usually available to polling-style interfaces (such as select(2) or poll(2)) so your standard event loop handler can discover client quits and handle them.

    • The client program can unexpectedly quit. In this case, the client’s TCP implementation will probably send FIN packets, but it might not be in an “expected” place in your application’s input parser. Be prepared to handle zero-byte reads or EOF reads that indicate a premature application termination.

    • The client host can unexpectedly die. In this case, the client’s TCP implementation won’t be able to send a FIN packet to your server and you will not receive any notification at all that the client connection has terminated. You can enable the TCP SO_KEEPALIVE socket option, but at least Linux defaults to a system-wide time of two hours of inactivity before sending the keepalive probes.

      If the system comes back up ‘quickly’, your application will receive either TCP RST packets in response or silence if a stateful firewall is configured to DROP packets that don’t match allowed or initiated traffic streams. The RST case can be detected similar to the FIN packets. The silence of dropped packets can only be detected with an application-level keepalive packet scheme.

    So it’s best to build in an application-level keepalive ping packet of some sort on a time frame that is acceptable to you. (For example, IRC uses PING and PONG packets to ensure clients are still connected to servers — the time between checks is configurable by network administrators.)

    How long you’ll go between pings and how many failed ping packets to accept depends heavily upon your application — you might be willing to allow twenty minutes to elapse before noticing and removing a disconnected client, or you might want to notice and remove a disconnected client after only twenty seconds. How long depends upon the working environment (20 seconds wouldn’t work for a Mars rover but might be ten times too long for a LAN-connected First-Person-Shooter video game) and network bandwidth available for “administrative overhead” like this.

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

Sidebar

Related Questions

I'm trying to implement a server-client socket program in Java that can support multiple
Difference between a bus error and a segmentation fault? Can it happen that a
Would you happen to know of any tools that can be used to find
I have a Node.js-Server with a socket.io-connection to a browser-client. sometimes the connection gets
Do you know how can I keep alive a socket connection if I do
Is there a "very bad thing" that can happen &&= and ||= were used
I know it's by design that you can't control what happens when an object
Can anybody please explain how this could possibly happen? I am completely aware of
I have a simple server that looks something like this: void *run_thread(void *arg) {
server: vxworks 6.3 calls the usual socket, bind, listen, then: for (;;) { client

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.