Problem with writing big data using java nio socket channel

I can send small data using java nio.

But if I want to send very large data then my socket channel is not working fine.

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

      

all data is sent.

I want to read data from the server, so I am using BufferedInputStreaReader.readLine (); In this case, I am not getting any error, nor can I get any of the data that I sent

Thanks Deepak

-3


a source to share


1 answer


write()

Returns:
The number of bytes written, possibly zero 

      

Write does not guarantee that you will write your entire buf. You need to check how much is written and write another one. (Maybe also wait (select) until you can write again.)



You can probably find a good java.nio tutorial too ... If you want a simple api use the io blocking in java.io instead ...

+1


a source







All Articles