public void close(int statusCode, HandshakeResponse errResponse) {
        log.warn("Closing connection with status: {}", statusCode);
        // remove handshake flag
        session.removeAttribute(Constants.HANDSHAKE_COMPLETE);
        // clear the delay queue
        queue.clear();
        // send http error response
        session.write(errResponse);
        // whether to attempt a nice close or a forceful one
        if (WebSocketTransport.isNiceClose()) {
            // now send close packet with error code
            IoBuffer buf = IoBuffer.allocate(16);
            buf.setAutoExpand(true);
            // all errors except 403 will use 1002
            buf.putUnsigned((short) statusCode);
            try {
                if (statusCode == 1008) {
                    // if its a 403 forbidden
                    buf.put("Policy Violation".getBytes("UTF8"));
                } else {
                    buf.put("Protocol error".getBytes("UTF8"));
                }
            } catch (Exception e) {
                // shouldnt be any text encoding issues...
            }
            buf.flip();
            byte[] errBytes = new byte[buf.remaining()];
            buf.get(errBytes);
            // construct the packet
            Packet packet = Packet.build(errBytes, MessageType.CLOSE);
            WriteFuture writeFuture = session.write(packet);
            writeFuture.addListener(new IoFutureListener<WriteFuture>() {

                @Override
                public void operationComplete(WriteFuture future) {
                    if (future.isWritten()) {
                        log.debug("Close message written");
                        // only set on success for now to skip boolean check later
                        session.setAttribute(Constants.STATUS_CLOSE_WRITTEN, Boolean.TRUE);
                    }
                    future.removeListener(this);
                }

            });
            // adjust close routine to allow for flushing
            CloseFuture closeFuture = session.closeOnFlush();
            closeFuture.addListener(new IoFutureListener<CloseFuture>() {

                public void operationComplete(CloseFuture future) {
                    if (future.isClosed()) {
                        log.debug("Connection is closed");
                    } else {
                        log.debug("Connection is not yet closed");
                    }
                    future.removeListener(this);
                }

            });
        } else {
            // force close
            CloseFuture closeFuture = session.closeNow();
            closeFuture.addListener(new IoFutureListener<CloseFuture>() {

                public void operationComplete(CloseFuture future) {
                    if (future.isClosed()) {
                        log.debug("Connection is closed");
                    } else {
                        log.debug("Connection is not yet closed");
                    }
                    future.removeListener(this);
                }

            });
        }
        log.debug("Close complete");
    }
public void close ( int statusCode , HandshakeResponse errResponse ) { log . warn ( "Closing connection with status: {}" , statusCode ) ; session . removeAttribute ( Constants . HANDSHAKE_COMPLETE ) ; queue . clear ( ) ; session . write ( errResponse ) ; if ( WebSocketTransport . isNiceClose ( ) ) { IoBuffer buf = IoBuffer . allocate ( 16 ) ; buf . setAutoExpand ( true ) ; buf . putUnsigned ( ( short ) statusCode ) ; try { if ( statusCode == 1008 ) { buf . put ( "Policy Violation" . getBytes ( "UTF8" ) ) ; } else { buf . put ( "Protocol error" . getBytes ( "UTF8" ) ) ; } } catch ( Exception e ) { } buf . flip ( ) ; byte [ ] errBytes = new byte [ buf . remaining ( ) ] ; buf . get ( errBytes ) ; Packet packet = Packet . build ( errBytes , MessageType . CLOSE ) ; WriteFuture writeFuture = session . write ( packet ) ; writeFuture . addListener ( new IoFutureListener < WriteFuture > ( ) { @ Override public void operationComplete ( WriteFuture future ) { if ( future . isWritten ( ) ) { log . debug ( "Close message written" ) ; session . setAttribute ( Constants . STATUS_CLOSE_WRITTEN , Boolean . TRUE ) ; } future . removeListener ( this ) ; } } ) ; CloseFuture closeFuture = session . closeOnFlush ( ) ; closeFuture . addListener ( new IoFutureListener < CloseFuture > ( ) { public void operationComplete ( CloseFuture future ) { if ( future . isClosed ( ) ) { log . debug ( "Connection is closed" ) ; } else { log . debug ( "Connection is not yet closed" ) ; } future . removeListener ( this ) ; } } ) ; } else { CloseFuture closeFuture = session . closeNow ( ) ; closeFuture . addListener ( new IoFutureListener < CloseFuture > ( ) { public void operationComplete ( CloseFuture future ) { if ( future . isClosed ( ) ) { log . debug ( "Connection is closed" ) ; } else { log . debug ( "Connection is not yet closed" ) ; } future . removeListener ( this ) ; } } ) ; } log . debug ( "Close complete" ) ; }
Close with an associated error status.

@param statusCode
@param errResponse