~/ learn/ comp-348/ cards/ OutputStream, and why flush() is not optional
1 of 4

Pack a protocol line into bytes, write once, flush

Pack a protocol line into bytes, write once, flush

Answer

byte[] line = ("PING " + n + "\r\n").getBytes(StandardCharsets.US_ASCII); out.write(line); out.flush();

One write means at most one segment on the wire instead of eight. The charset is named rather than defaulted, and flush() is what turns a queued buffer into a sent request — without it the peer waits forever.

Harold 4e ch2 §Output Streams

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/98abf9c9-82e8-420e-a1a0-a71da9b6763b/flashcard utf-8 LF