~/ 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/0ff32b1b-77af-4c9c-b9de-c75706a817b7/flashcard utf-8 LF