0

Does anyone know why in the Java Socket class, getInputStream reads bytes from the socket, while getOutputStream writes bytes to the socket? Intuitively I feel like reading should be an output stream, while writing should be an input stream.

1 Answer 1

2

The streams are named from your perspective. An input stream is a place where data is input to your program, and an output stream is a place where your program outputs data to.

No different from FileIn-/OutputStream, or System.in/out.

Even java.lang.Process is named this way (confusingly) - the getOutputStream method returns the other process's input stream, which you can write data to.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.