void writeClose ( int code , ByteString reason ) throws IOException { ByteString payload = ByteString . EMPTY ; if ( code != 0 || reason != null ) { if ( code != 0 ) { validateCloseCode ( code ) ; } Buffer buffer = new Buffer ( ) ; buffer . writeShort ( code ) ; if ( reason != null ) { buffer . write ( reason ) ; } payload = buffer . readByteString ( ) ; } try { writeControlFrame ( OPCODE_CONTROL_CLOSE , payload ) ; } finally { writerClosed = true ; } }
Send a close frame with optional code and reason .