Sign in to follow this  

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

This topic is 4388 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
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

This topic is 4388 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this