f low of d a t a (from a source β to a destin a tion) β’ Sequenti a l β’ One direction β’ InputStre a m β re a d d a t a β’ OutputStre a m β write d a t a For sockets: β’ You get two stre a ms β’ One for sending β’ One for receiving The socket itself does not send d a t a , Stre a ms do
to tre a t a ll these uniformly βWrite bytes here, they go somewhere.β Then progr a ms c a n inter a ct (s a me w a y) with: β’ Files β’ Network connections β’ Memory bu ff ers β’ Keybo a rds a nd screens
a InputStre a m / D a t a OutputStre a m - Structured bin a ry d a t a β’ Bu ff eredRe a der / PrintWriter- Hum a n-re a d a ble text β’ ObjectInputStre a m / ObjectOutputStre a m - J a v a objects
out.write(108); out.write(108); out.write(111); This sends "Hello"β¦ but: β’ H a rd to re a d β’ Error-prone β’ No structure β‘ We need higher-level stre a ms
a ms a re l a yered OutputStream os = socket.getOutputStream(); DataOutputStream dout = new DataOutputStream(os); E a ch l a yer: β’ Adds fe a tures β’ Still writes to the s a me destin a tion
DataOutputStream dout = new DataOutputStream(socket.getOutputStream()); This me a ns: β’ D a t a goes into dout β’ dout writes bytes β’ Bytes go through the socket β’ Server receives them
β’ Flushes rem a ining d a t a β’ Rele a ses system resources β’ Sign a ls end-of-communic a tion β In network progr a ms, closing often me a ns: βIβm done t a lking.β
Computing Javier Gonzalez-Sanchez, Ph.D. [email protected] Winter 2026 Copyright. These slides can only be used as study material for the class CSC 364 at Cal Poly. They cannot be distributed or used for another purpose. 31