code: protected void writeRequest(final NextFilter nextFilter,
              final SocksProxyRequest request) {
          try {
              boolean isV4ARequest = request.getHost() != null;
              byte[] userID = request.getUserName().getBytes("ASCII");
              byte[] host = isV4ARequest ? request.getHost().getBytes("ASCII")
                      : null;
  
              int len = 9 + userID.length;
  
              if (isV4ARequest) {
                  len += host.length + 1;
              }
  
              IoBuffer buf = IoBuffer.allocate(len);
  
              buf.put(request.getProtocolVersion());
              buf.put(request.getCommandCode());
              buf.put(request.getPort());
              buf.put(request.getIpAddress());
              buf.put(userID);
              buf.put(SocksProxyConstants.TERMINATOR);
  
              if (isV4ARequest) {
                  buf.put(host);
                  buf.put(SocksProxyConstants.TERMINATOR);
              }
  
              if (isV4ARequest) {
                  logger.debug("  sending SOCKS4a request");
              } else {
                  logger.debug("  sending SOCKS4 request");
              }
  
              buf.flip();
              writeData(nextFilter, buf);
          } catch (Exception ex) {
              closeSession("Unable to send Socks request: ", ex);
          }
      }
docs: Encode a SOCKS4/SOCKS4a 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.