How to close a blocked socket

D

Diego F.

Hello. I don't know how to force the closing of a blocked socket.

I have an server application that listens to a port. It works as it is very
simple, but I'm not sure about how to close the socket.

I use a thread to run the socket part, so I don't block the user interface.
If I close the application, and open again, the port is still in use.

I try to suspend the thread, but it doesn't work also.

How can I do that?
 
B

brianlanning

Hello. I don't know how to force the closing of a blocked socket.

I have an server application that listens to a port. It works as it is very
simple, but I'm not sure about how to close the socket.

I use a thread to run the socket part, so I don't block the user interface.
If I close the application, and open again, the port is still in use.

I try to suspend the thread, but it doesn't work also.

How can I do that?

When you created the thread that manages the socket, did you set the
IsBackground flag to true? If you do that, the OS will terminate your
child threads when the main application closes.

http://msdn2.microsoft.com/en-us/library/system.threading.thread.isbackground.aspx

brian
 
B

brianlanning

If I close the application, and open again, the port is still in use.

Check out SO_REUSEADDR also, although that will treat the symptom, not
the disease.

brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top