• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

timeout not working by the time of reading data from channel (urgent help please ..)

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please can any one help me why setSoTimeout() is not working?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
kishoret tata
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
does any one know why setSoTimeout() not working in blocking mode of SocketChannel?
Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic