Reputation: 43
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.
Upvotes: 0
Views: 32
Reputation: 58858
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.
Upvotes: 2