• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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
 
Our first order of business must be this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic