I have to send a dynamic buffer size to the socket stream.
It works correctly, but when I try to send multiple buffers with a size
bigger than
int my_buffer_size =18 * 1024
; (this is an indicative value)
I get the error (for some write):
Java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
My code is very simple: For example If I want to send a big file I read a file stream with
byte[] bs = new byte[my_buffer_size];
while (... ){
fileInputStream.read(bs);
byte[] myBufferToSend = new byte[sizeBuffer];
DataOutputStream out = new DataOutputStream(cclient.getoutputStream());
out.writeInt(myBufferToSend.length);
out.write(myBufferToSend);
out.flush();
}
(The file is just a test the buffer size can be variable)
the SendBufferSize is 146988.
Is there a way to fix the broken pipe error? I read around but actually I didn’t solve the problem.
Thank you any help is appreciated
I use the classic ServerSocket serverSocket; and Socket cclient