tags:

views:

669

answers:

1

I can sent small data using java nio.

But If I want to send a very large data then my socket channel did not work fine.

message = "very large data"+"\n";
ByteBuffer buf = ByteBuffer.wrap(message.getBytes());
int nbytes = channel.write(buf);

all the data is sent.

I want to read data from server so i am using BufferedInputStreaReader.readLine(); In this case I am not getting any error also i cannot retrieve any of the data that i have sent

Thanks Deepak

+1  A: 
write()

Returns:
The number of bytes written, possibly zero

Write is not guaranteed to write your whole buf. You need to check how much that was written, and do another write. (Probably also wait (select) until you can write again.)

You should probably also search for a good java.nio tutorial... If you need a simpler api, use the blocking io in java.io instead...

KarlP