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