Joey
Joey

Reputation: 43

Conceptual question on Java Socket Input/Output streams

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

Answers (1)

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

Related Questions