src/main/java/org/java_websocket/WebSocketImpl.java
public synchronized void closeConnection( int code, String message, boolean remote ) {
		if( readyState == ReadyState.CLOSED ) {
			return;
		}
		//Methods like eot() call this method without calling onClose(). Due to that reason we have to adjust the ReadyState manually
		if( readyState == ReadyState.OPEN ) {
			if( code == CloseFrame.ABNORMAL_CLOSE ) {
				readyState = ReadyState.CLOSING;
			}
		}
		if( key != null ) {
			// key.attach( null ); //see issue #114
			key.cancel();
		}
		if( channel != null ) {
			try {
				channel.close();
			} catch ( IOException e ) {
				if( e.getMessage().equals( "Broken pipe" ) ) {
					log.trace( "Caught IOException: Broken pipe during closeConnection()", e );
				} else {
					log.error("Exception during channel.close()", e);
					wsl.onWebsocketError( this, e );
				}
			}
		}
		try {
			this.wsl.onWebsocketClose( this, code, message, remote );
		} catch ( RuntimeException e ) {

			wsl.onWebsocketError( this, e );
		}
		if( draft != null )
			draft.reset();
		handshakerequest = null;
		readyState = ReadyState.CLOSED;
	}
public synchronized void closeConnection( int code, String message, boolean remote ) {
		if( readyState == ReadyState.CLOSED ) {
			return;
		}
		//Methods like eot() call this method without calling onClose(). Due to that reason we have to adjust the ReadyState manually
		if( readyState == ReadyState.OPEN ) {
			if( code == CloseFrame.ABNORMAL_CLOSE ) {
				readyState = ReadyState.CLOSING;
			}
		}
		if( key != null ) {
			// key.attach( null ); //see issue #114
			key.cancel();
		}
		if( channel != null ) {
			try {
				channel.close();
			} catch ( IOException e ) {
				if( e.getMessage().equals( "Broken pipe" ) ) {
					log.trace( "Caught IOException: Broken pipe during closeConnection()", e );
				} else {
					log.error("Exception during channel.close()", e);
					wsl.onWebsocketError( this, e );
				}
			}
		}
		try {
			this.wsl.onWebsocketClose( this, code, message, remote );
		} catch ( RuntimeException e ) {

			wsl.onWebsocketError( this, e );
		}
		if( draft != null )
			draft.reset();
		handshakerequest = null;
		readyState = ReadyState.CLOSED;
	}
public synchronized void closeConnection ( int code , String message , boolean remote ) { if ( readyState == ReadyState . CLOSED ) { return ; } //Methods like eot() call this method without calling onClose(). Due to that reason we have to adjust the ReadyState manually if ( readyState == ReadyState . OPEN ) { if ( code == CloseFrame . ABNORMAL_CLOSE ) { readyState = ReadyState . CLOSING ; } } if ( key != null ) { // key.attach( null ); //see issue #114 key . cancel ( ) ; } if ( channel != null ) { try { channel . close ( ) ; } catch ( IOException e ) { if ( e . getMessage ( ) . equals ( "Broken pipe" ) ) { log . trace ( "Caught IOException: Broken pipe during closeConnection()" , e ) ; } else { log . error ( "Exception during channel.close()" , e ) ; wsl . onWebsocketError ( this , e ) ; } } } try { this . wsl . onWebsocketClose ( this , code , message , remote ) ; } catch ( RuntimeException e ) { wsl . onWebsocketError ( this , e ) ; } if ( draft != null ) draft . reset ( ) ; handshakerequest = null ; readyState = ReadyState . CLOSED ; }
This will close the connection immediately without a proper close handshake.
The code and the message therefore won't be transfered over the wire also they will be forwarded to onClose/onWebsocketClose.

@param code    the closing code
@param message the closing message
@param remote  Indicates who "generated" <code>code</code>.<br>
<code>true</code> means that this endpoint received the <code>code</code> from the other endpoint.<br>
false means this endpoint decided to send the given code,<br>
<code>remote</code> may also be true if this endpoint started the closing handshake since the other endpoint may not simply echo the <code>code</code> but close the connection the same time this endpoint does do but with an other <code>code</code>. <br>
This will close the connection immediately without a proper close handshake . The code and the message therefore won t be transfered over the wire also they will be forwarded to onClose / onWebsocketClose .