Bookmark Topic Watch Topic
  • New Topic

any help on reading data please

tomerict erictomt
Posts: 2
  • Mark post as helpful
  • send pies
  • Report post to moderator
I am trying to read data into ByteBuffer using SocketChannel.
The following code working fine but the problem is with ByteBuffer size.
The data varies from request to request .
How do I read data into ByteBuffer with out specifing size .
The problem with size is some records has more than 500 bytes and some are less than 500 bytes.
How do i solve this problem ..
Is there any way to read data dynamically from socket channel ...
Any help on this please ...
Any sample I will aprricate ..
The data I have to read is in the following format ..
XXX ... yyyyy
etc ...

Here is my Code:
public ByteBuffer getResponse(byte[] request) throws Exception {
int lenth = 500;
InetSocketAddress isa = new InetSocketAddress("ip", port);
SocketChannel channel =;
ByteBuffer requestBuffer = ByteBuffer.wrap(request);
ByteBuffer responseByteBuffer = ByteBuffer.allocate(length);
int num = 0;
while (num == 0 ) {
num =;
return responseByteBuffer;

Please can any one tell me what changes do I need to read the data .
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't post duplicates Tom, it clutters the board and generally makes people less likely to help.
Also, I was fine with the Tom Eric name, but tomerict erictomt violates the "obviously fictitious" rule we have in our naming policy. Please change your display name.
    Bookmark Topic Watch Topic
  • New Topic