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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:49:10+00:00 2026-05-26T07:49:10+00:00

On the server side, I’m trying to gracefully close a connected socket. I know

  • 0

On the server side, I’m trying to gracefully close a connected socket. I know the proper sequence of events on the Socket should be:

  1. socket Shutdown with the SocketShutdown.Send option

  2. loop/wait until a socket Receive returns with 0 bytes

  3. socket Close

I have a few questions:

  1. what if Socket.Receive never returns (with 0 bytes)? will we be stuck trying to close the socket forever?

  2. whenever i call Close on the server, the Client always receives “an existing connection was forcibly closed by a remote host” exception on their end. how can i have the client notified of this close “gracefully”?

  3. on the server, if I’m using Async Begin/EndReceive calls, whenever I call Close on the socket, it ALWAYS results in an ObjectDisposedException on the Begin/EndReceive thread. Is there no way to Close a socket without this exception from occurring?

  • 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-26T07:49:11+00:00Added an answer on May 26, 2026 at 7:49 am
    1. The TCP protocol guarantees the socket will close eventually unless the peer refuses to allow it to close. In which case, you should wait forever or give up, whatever’s appropriate.

    2. If you close the socket after receive returns zero, that should not happen. If it is, your code is likely doing something wrong.

    3. You can’t release a resource while an asynchronous operation is or might be using it. Rather than calling close, call shutdown. Don’t call close until you’re 100% finished with the resource.

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

Sidebar

Related Questions

Developing server side code i finally got my eyes X-crossed trying to write -
I had problem triggering server side button click events so I found a solution
Having been primarily a server-side programmer(ASP.NET WebForms) I'm trying to get my mind wrapped
On server side I am using Connect and Socket.IO. I want to serve my
I am writing the server side of an UDP Socket in Processing and encountering
in server side, not browser.
ASP.NET server-side controls postback to their own page. This makes cases where you want
For RMI on server-side, do we need to start rmiregistry program, or just call
I'm writing server-side programs in PHP for an iPhone app. And I have no
I start a .Net server side program on my local workstation, but soon it

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.