Any Close payload was echoed back, a 1-byte one, a code that may not be sent and a reason that is not UTF-8 included. Echo a valid one and answer the others with 1002, from one place for both read loops.