views:

166

answers:

1

I want to use a SocketChannel and to have a timeout for its read/write methods. I've tried to set a timeout for the Socket that owns my SocketChannel like this :

channel.socket().setSoTimeout(TIMEOUT);

but that doesn't work. Is there any other solution?

+1  A: 

Also you can use ChannelWatcher :

 channel = SocketChannel.open(isa);  
 new ChannelWatcher(channel, 10000).start();  

isa is a InetSocketAddress

see :

http://java.sun.com/javase/6/docs/api/java/net/InetSocketAddress.html
http://java.sun.com/j2se/1.4.2/docs/api/java/nio/channels/SocketChannel.html

SjB
Where does ChannelWatcher come from?
It is a Java class that exist in JDK
SjB
I didn't find such a class in JDK. Tell me the package, please.
import java.nio.channels.SocketChannel
SjB
I was talking about ChannelWatcher.