code: func (s *Server) ServeConn(conn net.Conn) error {
  	defer conn.Close()
  	bufConn := bufio.NewReader(conn)
  
  	// Read the version byte
  	version := []byte{0}
  	if _, err := bufConn.Read(version); err != nil {
  		s.config.Logger.Printf("[ERR] socks: Failed to get version byte: %v", err)
  		return err
  	}
  
  	// Ensure we are compatible
  	if version[0] != socks5Version {
  		err := fmt.Errorf("Unsupported SOCKS version: %v", version)
  		s.config.Logger.Printf("[ERR] socks: %v", err)
  		return err
  	}
  
  	// Authenticate the connection
  	authContext, err := s.authenticate(conn, bufConn)
  	if err != nil {
  		err = fmt.Errorf("Failed to authenticate: %v", err)
  		s.config.Logger.Printf("[ERR] socks: %v", err)
  		return err
  	}
  
  	request, err := NewRequest(bufConn)
  	if err != nil {
  		if err == unrecognizedAddrType {
  			if err := sendReply(conn, addrTypeNotSupported, nil); err != nil {
  				return fmt.Errorf("Failed to send reply: %v", err)
  			}
  		}
  		return fmt.Errorf("Failed to read destination address: %v", err)
  	}
  	request.AuthContext = authContext
  	if client, ok := conn.RemoteAddr().(*net.TCPAddr); ok {
  		request.RemoteAddr = &AddrSpec{IP: client.IP, Port: client.Port}
  	}
  
  	// Process the client request
  	if err := s.handleRequest(request, conn); err != nil {
  		err = fmt.Errorf("Failed to handle request: %v", err)
  		s.config.Logger.Printf("[ERR] socks: %v", err)
  		return err
  	}
  
  	return nil
  }
docs: // ServeConn is used to serve a single connection.