| Author |
timeout not working by the time of reading data from channel (urgent help please ..)
|
kishoret tata
Greenhorn
Joined: Feb 15, 2004
Posts: 12
|
|
Hi, If I set timeout by the time of reading data from socket channel, but it is not working ... I set 30 seconds but it is not coming out after after 30 seconds ... it is taking more than 2 minutes .. Why is timeout not working ..... Here is my code ... SocketChannel channel = null; ByteBuffer requestByteBuffer = null; ByteBuffer buffer = null; ByteBuffer responseByteBuffer = ByteBuffer.allocate(100); InetSocketAddress isa = new InetSocketAddress("xx.xxx.xxx.xxx",yyyyy); try { channel = SocketChannel.open(isa); connected = channel.isConnected(); }catch (java.io.IOException ioe) { } try { requestByteBuffer = ByteBuffer.wrap(request, 0, request.length); channel.write(requestByteBuffer); // set timeout channel.setSoTimeout(30000); responseByteBuffer.rewind(); // Read bytes from the channel numRead = channel.read(responseByteBuffer); }catch(Exception e) { System.out.println("unable to read data from channel"); } finally{ if (channel != null) { try { channel.close(); // close the channel } catch (Exception e) {throw new RuntimeException(e);} } } Thanks.
|
 |
kishoret tata
Greenhorn
Joined: Feb 15, 2004
Posts: 12
|
|
|
Please can any one help me why setSoTimeout() is not working?
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24061
|
|
Well, one problem is that the code as written wouldn't compile. SocketChannel doesn't have a setSoTimeout() method. There's one in Socket, however, so you could call channel.socket().setSoTimeout(30000) instead. Give that a try.
|
[Jess in Action][AskingGoodQuestions]
|
 |
kishoret tata
Greenhorn
Joined: Feb 15, 2004
Posts: 12
|
|
Hi, I am sorry. I misstyped by the time of posting .. My code in class is : //set 30 seconds time out channel.socket().setSoTimeout(30000) This not working ... If I use channel.setSoTimeOut(30000) it doesn't compile first ... If I set timeout -1 then I am getting exception where as if I set 30 seconds it is not working ..it is taking more than 2 minutes. It is not coming out after 30 seconds ... Any ideas please ... Thanks.
|
 |
kishoret tata
Greenhorn
Joined: Feb 15, 2004
Posts: 12
|
|
Hi, does any one know why setSoTimeout() not working in blocking mode of SocketChannel? Thanks.
|
 |
 |
|
|
subject: timeout not working by the time of reading data from channel (urgent help please ..)
|
|
|