Forum Navigation
ServerSocket.accept and threading it
Posted: 03/28/09 21:13:39I am trying to make a server that accepts multiple connections and am completely new to doing any type of socket programming. I understand that the ServerSocket?.accept function just sits there and loops until someone tries to connect. Since it does this and I want the server to be able to do other things than sit there and wait for connections, I put the ServerSocket?.accept function into a thread that waits for connections and adds them to my list of connections when they are accepted/validated.
The problem I am having is, when I send the server shutdown command from the client, the main thread of the server shuts down, but the thread that waits for connections keeps waiting until one is made. Once one is made at that point it seg faults b/c the connections array no longer exists... I know that the thread continues to run b/c of the ServerSocket?.accept function just sits there and loops, is there any way to force that function to quit or gather a que of connections instead of just sitting there waiting for more? (built in...) I want all the threads to be shut down when the main thread shuts down...