Interrupting TCP Socket

In my application I build up TCP connections with the clients. We are in the developing phase so I need to reload the server frequently. The Server runs under tomcat, and when I try to stop the server, the Socket connection managing threads freeze and I have to kill whole tomcat to stop them. When the thread get an interruptedException it don't even notice it...

Until now I used socketTimeOut for my applications and a sleep at the end of the listening cycle as a breakpoint, but in this application I need to interrupt the already built sockets and the BufferedInputStream over it.

How can I solve this problem?

Thanks:

Bence

[661 byte] By [bencea] at [2007-11-26 12:36:14]
# 1
Hi,Do you have access to the stream? The thread will probably not get interrupted exception, but one way is to close the streams instead. The thread will in that case return from the blocking call.Kaj
kajbja at 2007-7-7 16:02:02 > top of Java-index,Archived Forums,Socket Programming...
# 2
Yeah, I have, but will it throw some kind of exception itself when it get an InterruptedException(i haven't recognized something like this), or do I have to put a sleep(1) into the end of the listening cycle, and catch the InterruptedException myself?Thanks:Bence
bencea at 2007-7-7 16:02:02 > top of Java-index,Archived Forums,Socket Programming...
# 3

Create SocketChannels and ServerSocketChannels, and get the sockets from them. Stay in blocking mode and proceed as before once you have these sockets. You can interrupt blocking operations (accept(), read(), write() on this kind of socket with Thread.interrupt(). This will close the socket and throw java.nio.channels.ClosedByInterruptException.

ejpa at 2007-7-7 16:02:02 > top of Java-index,Archived Forums,Socket Programming...
# 4
And how can I bind the SocketServer into a port only? When I made it with the default constructor i could define the port to bind. Now -- with nio --I only see possibilities to bind to ip&port.ThanksBence
bencea at 2007-7-7 16:02:02 > top of Java-index,Archived Forums,Socket Programming...
# 5
Thanks for the help.I already find the 'serverSocket.bind(new InetSocketAddress(port));' solution for the problem. And it is interruptible...Regards:Bence
bencea at 2007-7-7 16:02:02 > top of Java-index,Archived Forums,Socket Programming...