code: private void writeRequest(final NextFilter nextFilter,
              final SocksProxyRequest request, int step) {
          try {
              IoBuffer buf = null;
  
              if (step == SocksProxyConstants.SOCKS5_GREETING_STEP) {
                  buf = encodeInitialGreetingPacket(request);
              } else if (step == SocksProxyConstants.SOCKS5_AUTH_STEP) {
                  // This step can happen multiple times like in GSSAPI auth for instance
                  buf = encodeAuthenticationPacket(request);
                  // If buf is null then go to the next step
                  if (buf == null) {
                      step = SocksProxyConstants.SOCKS5_REQUEST_STEP;
                  }
              }
  
              if (step == SocksProxyConstants.SOCKS5_REQUEST_STEP) {
                  buf = encodeProxyRequestPacket(request);
              }
  
              buf.flip();
              writeData(nextFilter, buf);
  
          } catch (Exception ex) {
              closeSession("Unable to send Socks request: ", ex);
          }
      }
docs: Encodes a SOCKS5 request and writes it to the next filter
  so it can be sent to the proxy server.
  
  @param nextFilter the next filter
  @param request the request to send.
  @param step the current step in the handshake process