public WebSocket disconnect ( int closeCode , String reason , long closeDelay ) { synchronized ( mStateManager ) { switch ( mStateManager . getState ( ) ) { case CREATED : finishAsynchronously ( ) ; return this ; case OPEN : break ; default : // - CONNECTING // It won't happen unless the programmer dare call // open() and disconnect() in parallel. // // - CLOSING // A closing handshake has already been started. // // - CLOSED // The connection has already been closed. return this ; } // Change the state to CLOSING. mStateManager . changeToClosing ( CloseInitiator . CLIENT ) ; // Create a close frame. WebSocketFrame frame = WebSocketFrame . createCloseFrame ( closeCode , reason ) ; // Send the close frame to the server. sendFrame ( frame ) ; } // Notify the listeners of the state change. mListenerManager . callOnStateChanged ( CLOSING ) ; // If a negative value is given. if ( closeDelay < 0 ) { // Use the default value. closeDelay = DEFAULT_CLOSE_DELAY ; } // Request the threads to stop. stopThreads ( closeDelay ) ; return this ; }
Disconnect the WebSocket .