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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:32:19+00:00 2026-05-28T04:32:19+00:00

What is the recommended way to gracefully close a TCP socket? I’ve learned that

  • 0

What is the recommended way to “gracefully” close a TCP socket?

I’ve learned that close()ing before read()ing all the remaining data in my host buffer can cause problems for the remote host (he could lose all the data in his receive buffer that has been acked, but not yet been read by his application). Is that correct?

What would be a good approach to avoid that situation? Is there some way to tell the API that I don’t really care about data being lost due to my ignoring any remaining buffered data and closing the socket?

Or do I have to consider the problem at the application protocol level and use some kind of implicit or explicit “end of transmission” signal to let the other party know that it’s safe to close a socket for reading?

  • 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-28T04:32:19+00:00Added an answer on May 28, 2026 at 4:32 am

    1) Call shutdown to indicate that you will not write any more data to the socket.

    2) Continue to read from the socket until you get either an error or the connection is closed.

    3) Now close the socket.

    If you don’t do this, you may wind up closing the connection while there’s still data to be read. This will result in an ungraceful close.

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

Sidebar

Related Questions

What is recommended way to keep a user configuration data in Unix/Linux? My programming
What's the recommended way of creating a Data Access layer in real-life ASP.NET MVC
What is the recommended way of converting between Data.Vector.Unboxed and Data.Vector . Specifically, I
Or what's the recommended way to read and write at the same time? Having
What's the recommended way to structure html that includes navigation so it's still SEO'able
I know that for a modal view controller the recommended way of dismissing it
Is there a recommended way of implementing a series of activities such that the
What is the recommended way to add jQuery (or any script) BEFORE the rest
What's the recommended way to use Maven for a project that might grow large
What is the recommended way to embed PDF in HTML? iFrame? Object? Embed? What

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.