How to make Socket.receive() Interruptible?
Hello
I'd like to receive Tcp or Udp packages regularly, but the receive() return when an InterruptedException occurs, so my thread could block all my Application and make a kind of freeze untill stopping.
I set the SocketTimeOut, but it throws Exceptions regularly. So I'm looking for a clear method to solve this problem.
I'm open for everything, but prefer solutions without polling...
I have this problem with HttpClient too, so I would be glad if you could tell me a solution with httpclient.executeMethod(post) too.
Thanks:
Bence
[582 byte] By [
Bencea] at [2007-10-3 8:34:26]

Hello, jordanYeah, I know, that they can do this, but how?It seems too complicated to me. Could you give me a clue how can I start the work with them?An example code or tutorial would be useful.Thanks:Bence
Hello
I've found some example code in the [java home]/sample/nio/server but there are 25 different Java classes there. I've found out how can I make a SocketConnection and bind it to an InetAddress, and port, but I don't understand how can I receive and send...
Any tips?
And what about UDP?Are there any differences between TCP and UDP?
In the other hand I need to bind the Connection to a Network Interface. Do somebody know how can I do that?
Thanks:
Bence
I'd go back to your blocking-mode solution if you don't already understand NIO. If you set a read timeout of course it's going to trigger, that's what it's for. How often is up to you. And don't interrupt threads that are doing socket I/O!
ejpa at 2007-7-15 3:41:55 >

Hello
Why not interrupt? SocketTimeoutException do the same. In the other hand: what can I do, when my application is waiting for a connection, and I'd like to stop it?
I'm interested in nio, but the API seems so complicated to me. Could you suggest me some "tutorial", or "getting started" document?
Thanks:
Bence