update in java9: https://docs.oracle.com/javase/9/docs/api/java/io/InputStream.html#transferTo-java.io.OutputStream-
I saw some similar, but not absolutely necessary flows.
I have a server that will basically receive data from client, client A and forward it, byte for byte, to another client, client B.
I want to connect my client A input stream to my client B output stream. Is this possible? What are the ways to do this?
In addition, these clients send each other messages that are somewhat time sensitive, so buffering will not be performed. I do not want the buffer to say 500, and the client sends 499 bytes, and then my server holds 500 bytes when forwarding because it did not receive the last byte to fill the buffer.
Currently, I am parsing each message to find its length, then reading the length bytes and then forwarding them. I decided (and experienced) that it would be better than reading a byte and forwarding the byte again and again, because it would be very slow. I also did not want to use a buffer or timer for the reason that I mentioned in my last paragraph - I do not want messages to wait a very long time to go through simply because the buffer is not full.
What a good way to do this?
java inputstream outputstream
jbu Oct 15 '09 at 20:29 2009-10-15 20:29
source share