tomerict erictomt

Greenhorn
+ Follow
since Nov 12, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by tomerict erictomt

hi,
I tried with ByteOutputStream but not working ..
please can you give sample code how to read data into ByteOutputStream or
into ByteBuffer or what changes do i need to do in my code .
Thanks.
21 years ago
Hi,
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
AAA
BBBBBBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCCCC
DDDDDDDDDDDDDDDDDDDDDDd
etc ...

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

Please can any one tell me what changes do I need to read the data .
Thanks.
21 years ago