This content has been marked as final. Show 5 replies
There is: read(byteb, int off, int b)Then you have a design problem. The sender should also send information about that. Usually one sends a "length" value, followed by the bytes. Then on the other side you of course first read the "length" so you know how many bytes there are to read after that.
but I don't know before hand how many bytes are send
from the client....
I found the read and write methods in the BufferedOut/InputStream
I have this on the client side:
public int read(byte b, int off, int len) throws IOException public void write(byte b, int off, int len) throws IOException
I have this on the server side:
outBytes = new BufferedOutputStream(socket.getOutputStream()); String pp = "sally"; byte  vv = pp.getBytes(); int len = vv.length; outBytes.write(vv, 0, len);
but I am not sure how to obtain the arguments in the read call. Should I make an extra call from the client only specifying the length of the byte?
inBytes = new BufferedInputStream(socket.getInputStream()); inBytes.read(b, off, len)
when making: outBytes.write(vv, 0, len); the len is the correct value so it seems silly to send that separatly...
when making: outBytes.write(vv, 0, len); the len is the correct value so it seems silly to send that separatly...You misunderstand what that argument is for. It is just to tell it how many bytes from the array to write. It does not also tell it to actually write the number itself too. If you need to know the number of bytes written (so that the receiver in your case can know how many bytes to read), then that value needs to be made available somehow. Writing the length before the bytes would be a way to do that.