Jump to content
  • Advertisement
Sign in to follow this  
Billr17

[.net] System.Net.Sockets.Socket and killing Accept on close event.

This topic is 4638 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a multi threaded server program using the Socket object. My issue is with killing the Accept method within my thread. When my application is closed the thread cannot exit until the Accept method stops blocking. I have tried manually Aborting the thread and it still hangs. After doing a search on google I found some similar issues posted online. The sugestion was to just close the server's socket and catch the exception that the Accept method will throw (10004 - WSAEINTR - Interrupted function call. This error indicates that a blocking call was interrupted by a call to WSACancelBlockingCall). Is this in fact the correct method for dealing with this issue, or is there a better way? This seems to work, but produces a slight delay when when the application is closing. Thanks. Bill

Share this post


Link to post
Share on other sites
Advertisement
I agree on DaWanderer's approach. Use the Asynchronous methods(BeginAccept/EndAccept, BeginReceive/EndReceive). These are far more flexible, and don't require you to constantly poll the sockets for data, which is tedious.

Also, it uses the .NET event sinks to the max, which is always good in making your code easier to read.

Toolmaker

Share this post


Link to post
Share on other sites
i just mark such threads as IsBackground = true, thus they get killed when the all non-background (the mainthread..) - threads die.

but recently, i moved to async networking, and it works quite well, too..

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!