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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:52:10+00:00 2026-06-02T03:52:10+00:00

For non-blocking sockets, I know that recv() will return 0 with no error code

  • 0

For non-blocking sockets, I know that recv() will return 0 with no error code if the remote client has gracefully disconnected (assume we are the server). How would you detect abnormal disconnection? Will recv() still return 0, or is there some other way to use the API to detect this?

  • 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-06-02T03:52:13+00:00Added an answer on June 2, 2026 at 3:52 am

    If connection is physically broken or the other host has shut down without gracefully closing the socket your recv will be waiting forever. At the socket level, you can use select() and set timeout for waiting data to be available for reading on the socket. You’ll have this in a loop and if data is available – read it (recv()); if select() times out, close the socket gracefully and reconnect.

    Another solution would be having implemented keep-alives in your protocol. One side is periodically sending keep-alive messages and another side has a timer with a timeout set (adjusted to sending period) and is waiting for them. If timer times out, “waiting” host closes its socket and tries to reconnect.

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

Sidebar

Related Questions

I know that read() is a blocking call unless I make the socket non-blocking.
I am writing a client - server system in which I used NON-BLOCKING sockets.
I am trying to use non-blocking TCP sockets. The problem is that they are
I'm programming a server and a client using non blocking sockets ( fd_sets and
I have a unit test that checks behavior on blocking and non-blocking sockets -
I'm learning to write non-blocking server and client applications using epoll, poll, etc. and
I'm trying to write a non-blocking client and non-blocking server with requirements: Server just
Can anyone please enlighten me about current .NET socket techniques? Non-blocking sockets If I
I am currently using a non-blocking SocketChannel (Java 1.6) to act as a client
Should sockets be set to non-blocking when used with select.select in Python? What difference

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.