• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SocketChannel question

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using JavaNIO for my socket application. Earlier I was using input output streams. Inputstream has a method called "available" that, without blocking, returns the number os bytes available for reading from the socket. Is there any similar method which i can use with SocketChannel for reading the data from socket. Basically I wanted to know how much the tcpip buffer is getting full before read on the channel returns or simply finding it out how many bytes are available for reading.

I apprecaite your response.

Thanks,
Basheer
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using non-blocking sockets, you can't rely on available() anymore. You have to call the read method in the SocketChannel with a byte buffer and check that you have read enough data: "read() cannot read any more bytes than are immediately available from the socket's input buffer".

As usual I'd recommend using a framework. And for writing high-performance network apps I'd suggest: http://directory.apache.org/subprojects/mina/getting_started.html

I've used it succesfully in a project that required non-blocking sockets.

/M
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic