docs: public WebSocket connect() throws WebSocketException
      {
          // Change the state to CONNECTING. If the state before
          // the change is not CREATED, an exception is thrown.
          changeStateOnConnect();
  
          // HTTP headers from the server.
          Map<String, List<String>> headers;
  
          try
          {
              // Connect to the server.
              mSocketConnector.connect();
  
              // Perform WebSocket handshake.
              headers = shakeHands();
          }
          catch (WebSocketException e)
          {
              // Close the socket.
              mSocketConnector.closeSilently();
  
              // Change the state to CLOSED.
              mStateManager.setState(CLOSED);
  
              // Notify the listener of the state change.
              mListenerManager.callOnStateChanged(CLOSED);
  
              // The handshake failed.
              throw e;
          }
  
          // HTTP headers in the response from the server.
          mServerHeaders = headers;
  
          // Extensions.
          mPerMessageCompressionExtension = findAgreedPerMessageCompressionExtension();
  
          // Change the state to OPEN.
          mStateManager.setState(OPEN);
  
          // Notify the listener of the state change.
          mListenerManager.callOnStateChanged(OPEN);
  
          // Start threads that communicate with the server.
          startThreads();
  
          return this;
      }